Cricket Simulator

johndo

Member
Hi everyone,
I wrote a very basic code for a cricket(insect) sound simulator.It works on the sim in prog editor perfectly,but does not work properly on chip.There is nothing wrong with the chip,as i can download other programs to it and works fine.
What i need is a random number of chirps(b6=up to 5 chirps)and random time interval between the chirps(b7=up to 10 secs plus loop to minutes)and random switch to a second cricket sound(cricket1:).When downloaded to the chip it just keeps chirping constantly and does not stop. What am i doing wrong? I realize the codes probably a bit clunky!
It's a 28x 4Mhz...Thank you...

cricket: random b6
b6=b6/50
for b4= 0 to b6
for b0 = 1 to 2
for b1 = 1 to 3
sound 0,(125,1)
pause 20
next b1
pause 100
next b0
pause 450
next b4


waiting: random b7
b7=b7/25
w5=b7*1000
low 0
for b3= 1 to 1
pause w5
next b3
if b6=1 then cricket1
random b6
goto cricket

cricket1: for b5=1 to b7
sound 0,(125,3)
pause 5
pause 350
sound 0,(125,3)
pause 5
pause 29
sound 0,(125,3)
pause 5
low 0
wait 3
next b5
random b6
random b7
goto waiting
 

Technical

Technical Support
Staff member
random should be used on a word variable - see the decsription in part 2 of the manual. Use on a byte variable will not work as expected.
 

johndo

Member
Thanks Technical, Ive rewritten it and borrowed some of hippy's "random" code...SEEMS to be working ok now...Chirp's a random number of times with a delay between chirp's of up to ten minutes,and switches between different chirp's at random...Next i want to hook up a light and sound sensor to simulate real cricket behavior... Thanks for a great website,and thanks hippy...Here's the code...Learning all the time:)

cricket: random w0
b2=w0/5//6+1
for b1=1 to b2
for b5 = 1 to 3
sound 0,(125,1)
pause 22
next b5
pause 100
for b5 = 1 to 3
sound 0,(125,1)
pause 22
next b5
pause 1100
next b1
goto waiting

waiting: random w3
b7=w3
sleep b7
if b2=3 then cricket1
goto cricket

cricket1: random w0
b2=w0/5//6+1
for b1=1 to b2
sound 0,(125,3)
pause 5
pause 350
sound 0,(125,3)
pause 5
pause 30
sound 0,(125,3)
pause 5
low 0
wait 2
next b1
b2=0
goto waiting
 

Rickharris

Senior Member
Thanks for posting your improved code - Nice to see other peoples results. Keep on experimenting.

Mmm might make a cricket myself.
 
Top