' picaxe metronome ' 1 2007 by A. Stein, Medcosm, LLC ' ' created to help student musicians with rhythm ' ' Use this prog w/ metronome V2 circuit ' ' Features: adjustable BPM from 60-240, 2 button control, 3/4 and 4/4 time ' ' 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 'hardware hookups for this project symbol PIEZO1=1 'piezo 1 out symbol BUTN1=pin3 'N.O. pushbutton 1 symbol BUTN2=pin4 'N.O. pushbutton 2 'declare variable space symbol mode=b0 'mode symbol bpm=b1 'beats per minute (frequency) symbol bpmPause=w1 'period of bpm symbol beat=b6 'current beat (0, 1, 2,or 3 max) symbol changedMode=b7 'flag for mode change 'static vars symbol minBPM=60 'min bpm symbol maxBPM=240 'max bpm symbol BPMchange=8 'BPM change per beat on buttonpress symbol note1=80 'note of first tic symbol duration1=2 'duration of first tic symbol note2=130 'note of other tics symbol duration2=4 'duration of other tics 'available modes=modeOff, mode44, mode34 symbol modemax=2 'highest mode available 'init modes and vars init: bpm=120 mode=1 'set new BPM and start playing 'main loop start: changedMode=0 if BUTN1=1 and BUTN2=1 then 'if both buttons pressed mode=mode+1 'then change mode changedMode=1 endif if mode=0 and BUTN1=1 then 'if off and either button press mode=1 'then turn on elseif mode=0 and BUTN2=1 then mode=1 endif if mode > modemax then 'if end of modes, turn off mode=0 endif if BUTN1=1 and changedMode=0 then 'if BUTN1, decrease BPM BPM=BPM-BPMchange endif if BUTN2=1 and changedMode=0 then 'if BUTN2, increase BPM BPM=BPM+BPMchange endif 'check BPM limits if BPM > maxBPM then BPM=maxBPM elseif BPM < minBPM then BPM=minBPM endif branch mode, (modeOff, mode44, mode34) 'execute desired mode 'powerdown for a bit to save battery modeOff: nap 5 goto start mode44: if beat>3 then beat=0 endif goto playbeat mode34: if beat>2 then beat=0 endif goto playbeat 'play a beat, 1st beat of measure is different than others playbeat: if beat=0 then 'play 1 beat of measure different sound piezo1,(note1,duration1) else sound piezo1,(note2, duration2) endif bpmPause=1000*60/bpm 'compute BPM period pause bpmPause 'and pause for it beat=beat+1 'increment beat number goto start