TheFunkyOne
New Member
Hello! I am using a 08m chip and have adapted code provided by chipwich for a $5 beatbox. I removed the powerdown stuff as I am attached to a powerpack, and changed the symbols back to their original meanings. The code works great, I am using peizos attached to sticks instead of LDRs. My question is: what is the best way to put in a playback switch: i.e. when pin3 = 0 then record, and when pin3 = 1 then playback?
here is the code as it stands. Cheers guys!
here is the code as it stands. Cheers guys!
Code:
init:
start:
high 0
pause 500
w2 = 0
b10=0
record:
do
readadc 1, b0
readadc 2, b1
b11 = 0
if b0>20 then
b11 = 1
endif
if b1>10 then
b11=2
endif
'if b1>20 then
'b11=3
'endif
if b10!=0 or b11!=0 then
savesample:
b2 = b11
gosub getsamplebyte
if b13 = 0 then
b11 = 0
endif
b2 = b2*b7
b11 = b11|b2
endsavesample:
b6 = $50 + b12
poke b6, b11
b10 = b10 + 1
else
w2 = w2 + 1
endif
pause 20
loop while b10<184
low 0
findlastbeat:
b8 = 0
for b10 = 1 to 184
gosub getsample
if b11>0 then
b8 = b10 - 1
endif
next b10
w2 = 0
playsoundloop:
b0 = 255
b2 = 255
low 0
for b10 = 0 to b8
gosub getsample
if b11 = 0 then
pause 20
b1 = 0
elseif b11 = b1 then
sound 4, (60, 2)
elseif b11 = 2 then
sound 4, (100, 2)
'elseif b11 = 3 then
'sound 4, (120, 2)
endif
b1 = b11
if b0>140 and b2>160 then
readadc 1, b0
readadc 2, b2
endif
w2 = w2 + 1
next b10
goto start
getsamplebyte:
b12 = b10/4
b13 = b10%4
lookup b13, (1, 4, 16, 64), b7
b6 = $50 + b12
peek b6, b11
return
getsample:
gosub getsamplebyte
b9 = b7*3
b11 = b11 & b9
b11 = b11/b7
endgetsample:
return
Last edited by a moderator: