' ' Tic Tac Beat Box - (c) Andy Stansfield 19/7/2009 (Andy Gadget) ' Released under Attribution - Non commercial - No derivs license ' ' Touch anywhere on the top track to turn on. ' It will then compose and play beat rhythms (1 to 5 beats) at various tempos. ' It composes two bars full and chooses between these randomly. ' It starts a new rhythm approximately every 30 seconds. ' ' Turn off by touching the top track again. ' ' Note : This powers up in 'sleep' mode and wakes every 4 seconds to see if ' anything is happening. It may not be awake when the PC tries to communicate. ' Simplest way around is to turn it on first - ' ' V1.0 Initial release #picaxe 08m disablebod data (0,0,0,0,0,0,0,0,0,0) 'reserve space for beat data (2 bars worth) symbol rnd = w6 '16 bit random number storage symbol rnd_h = b13 'High byte of random number symbol rnd_l = b12 'Low byte of randon number symbol led = 1 symbol cnt = b11 'Loop counter symbol beats = b10 'Beats in measure symbol tempo = b9 'Tempo of song symbol stime = b8 'Number of measures in song symbol instr = b7 'Instrument number symbol rest = b6 'Pause to set tempo symbol adc = b4 'ADC reading - turns on and sets random seed. symbol tmp3 = b2 'Temp variable symbol tmp2 = b1 'Temp variable symbol tmp1 = b0 'Temp variable PwrSave: do sleep 4 readadc 4, adc 'Read value from adc loop until adc>128 'Switch on if top track touched rnd_l = adc 'ADC value sets seed for RANDOM command rnd_h = rnd_l 'Double up to make word from bytes random rnd 'Gen.first 16 bit random number from seed tune 0,4,(84,89) 'Beep to acknowledge turn-on pause 200 do 'This is the start of the main loop 'Set up the rhythm strings beats = rnd_l AND %00000011 + 2 '2 to 5 beats tempo = rnd_h AND %00001111 + 1 '1 to 8 stime = 512 / beats / tempo 'Time for tune will vary with beats and tempo rest = tempo * 50 'Less rest between beats = faster tempo tmp1 = beats * 2 - 1 for cnt = 0 to tmp1 random w6 instr = rnd_l AND %00000111 'Random selection of one of 8 notes, write cnt,instr 'Store it in data area at beginning of memory next cnt for cnt = 1 to beats 'LED flashes to show beats of rhythm before play high led pause 5 low led pause 200 next cnt ' Play the rhythm for tmp3 = 1 to stime 'Stime is rhythm run count random w6 tmp1 = rnd_h AND %00000001 * beats 'Pointer to phrase is 0 or beats value tmp2 = tmp1 + beats 'so selects phrase to play for cnt = tmp1 to tmp2 read cnt,instr 'Read the instrument to play from data area on instr goto snare,cowbell,trill,shake,scrape,lobel,midbel,hibel cont: pause rest 'Using goto instead of gosub saves 14 bytes! next cnt readadc 4, adc 'Read value from adc if adc > 128 then pwrsave 'Shut down if top track touched high led 'Very brief flash each bar low led next tmp3 loop snare: sound 2,(254,3,240,3,230,8) 'These are the various percussion sounds. goto cont cowbell: sound 2,(120,1,110,2,0,11) goto cont trill: sound 2,(122,1,10,2,122,1,10,2,0,8) goto cont shake: sound 2,(200,1,255,10,0,3) goto cont scrape: sound 2,(250,3,251,3,252,3,254,5) goto cont lobel: sound 2,(120,4,0,10) goto cont midbel: sound 2,(122,4,0,10) goto cont hibel: sound 2,(124,4,0,10) goto cont