Wednesday, January 26, 2011

Tuesday week 3 - Hacking a Toy

Today I spent the class time working on hacking my toy. The first thing i wanted it to do was to move the head to the beat of a song. So I built a circuit that took an audio input, passed thru a low pass filter and into the PIC ADC. This way, everything but the kick drum would be filtered out. I wrote a simple program that triggered an output to the motors when the ADC voltage peaked from the kick so the fish would headbang to the beat. It worked quite well for the song I tweaked it to, but had to be tweaked for every song played. I only had 3 I/O pins on my PIC available and eventually disassembled the circuit in pursuit of more user interactive control.

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