' Picaxe toothbrush timer ' Indicates how long to brush your teeth so that ' they don't turn yellow or disappear! ' ' (C) 11/07 The Steins ' ' Info: ' ' The first microcontroller program for some of us... ' ' ' Version History: ' ' v1 - Initial version ' v2 - standard optimizations with subroutines ' v3 - touch switch (didn't work well) ' v4 - added heartbeat LED flash ' ' ' 08M variable table (for convenience) ' b0:b1 b2:b3 b4:b5 b6:b7 b8:b9 b10:b11 b12:b13 ' w0 w1 w2 w3 w4 w5 w6 ' ' 'pinouts symbol LED=1 'LED pinout symbol SPKR=2 'speaker pinout symbol BTN=pin3 'N.O. pushbutton switch to start timer 'vars symbol i=b0 'loop counter symbol j=b1 'tmp variable symbol numOfFlashes=w2 'number of LED flashes for each 1/4 of timer 'constants symbol shortdly=100 'timing delay between beeps (milliseconds) symbol LEDdly=500 'timing delay for LED(milliseconds) symbol beeptone=100 'beep tone symbol endtone=50 'end tone symbol heartBeatCtr=60 'heartbeat counter 'initialization routines init: numOfFlashes=30*500/LEDdly 'calculate correct num of Flashes for 30 second delay 'main execution starts here start: checkSwitch: j=j+1 if j>heartBeatCtr then 'if it is time, then flash heartbeat high LED pause 100 low LED j=0 'reset counter endif if BTN=0 then 'check if switch is pressed nap 4 'powerdown for .25 seconds (approx) goto checkSwitch end if gosub beep gosub flashAndWait gosub beep gosub beep gosub flashAndWait gosub beep gosub beep gosub beep gosub flashAndWait gosub beep gosub beep gosub beep gosub beep gosub flashAndWait sound SPKR,(endtone,200) 'play a beep sound goto start 'start again 'flash LED and wait for a certain amount of time flashAndWait: for i=1 to numOfFlashes high LED pause LEDdly low LED pause LEDdly next i return 'beep piezo and pause briefly beep: sound SPKR,(beeptone,25) 'play a beep sound pause shortdly return