I went back to my old code for moving the fish head around and added some sound capabilities. I wired up the outputs to a speaker and to a darlington transistor for motor control. The fish has 2 functions: "Talk" and "Spaz"
The talk sequence causes the fish to perk up, open it's mouth, and generate a series of random pitches. It's speaks binary! I first had the Pic simply driving a piezo element as a speaker but it simply wasn't loud enough. So I built a simple 1 transistor darlington audio amplifier and used the on-board speaker on the fish. I used the following schematic.
The circuit:
The code:
main:
serout 0,N2400,(10,13,"\nI are binary fish")
serout 0,N2400,(10,13,"Press T for talk, ")
serout 0,N2400,("Press S to spaz")
serin 1,N2400,b1
if b1="s" then spaz
if b1="t" then talk
pause 100
goto main
spaz:
serout 0,N2400,(10,13,"\nHeRpA dErP!")
for b6 = 1 to 15
random w0
w1 = b1/127
w2 = b1/2
high 4
pause w2
random w0
w1 = b1/127
w2 = b1/2
low 4
pause w2
next b6
goto main
talk:
serout 0,N2400,(10,13,"\n11001010 10011011!!!")
for b7 = 1 to 50
high 4
random w0
w1 = b1+500
sound B.2,(b1,7)
next b7
low 4
goto main
No comments:
Post a Comment