Originally Posted by Otaku
So you simply load a single universal program? Does the board power the servo, or is a separate supply needed?
Yes, the program to convert the audio to the servo movement is very short. Here's what I'm starting with -
'08 Picaxe Audio/Servo driver
'b1 byte variable 0-255 in 10uS increments.
'b2 Pause variable 0-65535 in 1mS increments.
'Hitec servo's like signals between 0.740 and 2.740 mS and period of 1 to 20 mS
'C.0 is to audio player
'C.1 is from audio driver
'C.2 is PIR
'C.4 is Greeter jaw servo
Init: 'Just a starting point label
serout C.0,4800, ($EF); 'STOP MP3 module
serout C.0,4800, ($E1); 'Set MP3 volume
Do : Loop Until PIR_IN=1
PIR_COUNT = PIR_COUNT + 1 * PIR_IN
Loop Until PIR_COUNT = 10
PIR_COUNT = 0
Servo C.4,205 'Initialises Pin4 as a servo output and sets servo to the start position
serout C.0,4800,($01) 'Start playing first mp3
w3=5000 'Counter for number of loops needed, every 1000 = about 15 seconds +/-
b2=8 'Set pause delay
b3=178 'Set Servo Min position and also offset - mouth open
b4=204 'Set Servo Max position - mouth closed
Servopos C.4,b4 'Initialises Pin4 as a servo output and sets servo to the start position
ADCA: 'Reads input voltage in 256 steps Pin 1 (leg 6)
Readadc C.1,b0 'Read input voltage into b0
b1=225-b0+b3 'Add offset for servo's CCW output
If b1<b3 then gosub servomax 'Test for less than servo min position and if less, set at servo min
If b1>b4 then gosub servomin 'Test for more than servo min position and if more, set at servo max
MoveA: 'Move servoA
servopos C.4,b1 'Pulse pin 4 (leg 3) width=b1 - Using servopos can help prevent jitter
pause b2 'Wait Delay b2
w3=w3-1 'Decrement the counter
if w3>0 then goto OP 'Test for counter being larger than 0 if yes, go round the loop again
for time = 1 to 15 '60 is the number of seconds of retrigger delay
pause 1000 'Pause for 1 sec
I'm using a regulated 5V power supply to run the board and the servo and it seems to work fine.
I've modified the board to utilize the other 2 outputs and plan to have it triggered by a PIR. I'm using the Tenda triggerable audio device that outputs in stereo so that I can use a tone track to activate the servo.