;Touch_Synthesiser ;MODES can be created so different programs will run when Picaxe ;circuit is powered up. #no_data ;start up routine Memory: ;records b0 as either mode1 or mode2 read 0,b0 ;Read position 0 and put into b0 ;inc b0 ; Increase b0 by 1 dec b0 ;if b0 > 3 then ; If b0 is greater than the number of MODES (2 Modes) pause 30 if b0 = 0 or b0 > 2 then b0 = 2 ;Then make b0 = 1 endif write 0,b0 ;Write the new incremented value of b0 to position 0 ;debug main: choice: if b0 = 1 then ;Use value of b0 to send program to different MODES pulsout 0, 50 gosub mode1 endif if b0 = 2 then pulsout 0, 25 pause 100 pulsout 0,25 gosub mode2 endif goto main ;****************************MODE 1********************************* Mode1: touch16 [%11011001], 4,w1 ;tinker the first and last two bits (prescaler and post scaler) ;debug b6=w1 //255 ;debug pause 30 If b6 < 40 then input 2 goto mode1 endif readadc 1, b7 b7 = b7-100 ;lower the number b7 = b7 * 4 / 3 ;multiply by 1 and a bit b6 = b6 -30 ;lower the number near 0 b6 = b6*4 ;make the range bigger b8 = b6 + b7 ;add the touch and the potentiometer pitch w2 = b8 *2 ;make the period twice as big as the duty ;debug pwmout pwmdiv16, 2, b8, w2 goto mode1 ;********************MODE 2*************************************** Mode2: major_scale: touch16 [%11011001], 4,w1 w1=w1 //255 b10 = w1*5/4 ;debug if b10 < 50 then goto major_scale elseif b10 < 51 then b14 = 16 elseif b10 < 53 then b14 = 11 elseif b10 < 55 then b14 = 9 elseif b10 < 57 then b14 = 7 elseif b10 < 59 then b14 = 5 elseif b10 < 61 then b14 = 4 elseif b10 < 63 then b14 = 2 elseif b10 < 256 then b14 = 0 endif readadc 1, b11 ;w2 =w2//4 b11=b11/9 b11=b11//14 ;debug ;tune 1,1,(b14) tune 1,b11,(b14) pause w2 ;debug goto mode2