# Two Axis Eyes with Halstaff Picaxe Servo Control



## Dead Things (Apr 4, 2009)

These use three micro servos, two ping pong balls, some plumbing parts, aluminum flat stock and a couple drops of blood.
The movement is controlled by Halstaff's Picaxe 3 Axis servo board.


----------



## Lord Homicide (May 11, 2012)

That is pretty cool. How will the witch be incorporated into your haunt?


----------



## RoxyBlue (Oct 6, 2008)

Her eyelids could use a little oil

You got a very natural movement with the eyes with this set up.


----------



## tstraub (Feb 26, 2012)

Looks great Pat. I just watched you how to videos very informative.

Tyler


----------



## Headless (Sep 4, 2011)

Great job. I love the different colored eyes.


----------



## halstaff (Nov 18, 2009)

Looks great Pat!
Could you post the modified code you used so that I can add it to my library?
Thanks.


----------



## Dead Things (Apr 4, 2009)

RoxyBlue said:


> Her eyelids could use a little oil
> 
> You got a very natural movement with the eyes with this set up.


Thanks Roxy and yes, that is a very noisy servo! The other ones aren't noisy so it's either the quick movement or bad servo.



halstaff said:


> Looks great Pat!
> Could you post the modified code you used so that I can add it to my library?
> Thanks.


Here is the code I used. It is Halstaff`s code with some modifications in servo ranges and one of the delay times (symbol delay=10). I will probably drop some of the delay times in the Eyelid section as well (eg: pause 7500 to pause 3500)

CODE:
#Picaxe 08M2

'b18 byte variable 0-255 in 10uS increments.
'b15 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.1 is Eyes Left/Right servo
'C.2 is Eye Up/down servo
'C.4 is is Eye Lid servo

symbol Eyelr = C.1
symbol Eyeud = C.2
symbol Eyelid = C.4
symbol counter = b9
symbol pointer = b8
symbol delay = 10
symbol counter1 = b19
symbol pointer1 = b18
symbol delay1 = 39
symbol counter2 = b25
symbol pointer2 = b24
symbol delay2 = 45

start0:
pause 500

start1:'Eye Lids
let b8=133 'set pointer offset so that Eye Lid loop does not get stuck
let b6=130
let b7=130 'set default center values
servo Eyelid,pointer 'center servo
pause 7500
for counter = 130 to 83 step -1 
servopos Eyelid,counter
pause delay
next counter
pause 3000

for counter = 83 to 180 step 1
servopos Eyelid,counter 
pause delay
next counter
pause 3000

for counter = 180 to 130 step -1
servopos Eyelid,counter 
pause delay
next counter
pause 4000

move: random w3 'place a random number in wo (also B0 & B1)

if b7<83 then left 'check for random down
if b7>=83 and b7<=130 then middle 'check for random middle
if b7>=130 then right 
goto move 'keep moving the Eye Lid back to move loop

right: if pointer = 83 then move 
if pointer = 130 then mr 
for counter = 180 to 83 step -1 
servopos Eyelid,counter
pause delay
next counter
pointer = 83
goto skipmr

mr: for counter = 130 to 83 step -1 
servopos Eyelid,counter
pause delay
next counter
pointer = 83

skipmr: pause 7000 'delay to look natural
goto move 'return to move loop

middle: if pointer = 130 then move 'if Eye Lid is already in the middle then go back to move
if pointer = 83 then ml 
for counter = 180 to 130 step -1
servopos Eyelid,counter 
pause delay
next counter
pointer = 130
goto skipml

ml: for counter = 83 to 130 step 1
servopos Eyelid,counter 
pause delay
next counter
pointer = 130

skipml: pause 9000 'delay to look natural
goto move 'return to move loop

left: if pointer = 180 then move 
if pointer = 83 then lmr 
for counter = 130 to 180 step 1
servopos Eyelid,counter 
pause delay
next counter
pointer = 180
goto skiplmr

lmr: for counter = 83 to 180 step 1
servopos Eyelid,counter 
pause delay
next counter
pointer = 180

skiplmr: pause 7000 'delay to look natural
goto move 'return to move loop

start2:'Eye Left/Right
let b18=153 'set pointer offset so that Eye Left/Right loop does not get stuck
let b16=150
let b17=150 'set default center values
servo Eyelr,pointer1 'center servo
pause 8000
for counter1 = 150 to 125 step -1 
servopos Eyelr,counter1
pause delay1 
next counter1
pause 3000

for counter1 = 125 to 175 step 1
servopos Eyelr,counter1 
pause delay1
next counter1
pause 3000

for counter1 = 175 to 150 step -1
servopos Eyelr,counter1 
pause delay1
next counter1 
pause 2000

move1: random w8 'place a random number in wo (also B0 & B1)

if b17<125 then left1 'check for random left
if b17>=125 and b17<=150 then middle1 'check for random middle
if b17>=150 then right1 
goto move1 'keep moving the Eye Left/Right back to move loop

right1: if pointer1 = 125 then move1 
if pointer1 = 150 then mr1 
for counter1 = 175 to 125 step -1 
servopos Eyelr,counter1
pause delay1
next counter1
pointer1 = 125 
goto skipmr1

mr1: for counter1 = 150 to 125 step -1 
servopos Eyelr,counter1
pause delay1
next counter1
pointer1 = 125

skipmr1: pause 7000 'delay to look natural
goto move1 'return to move loop

middle1: if pointer1 = 150 then move1 'if Eye left/Right is already in the middle then go back to move
if pointer1 = 115 then ml1 'check to see if Eye is pointed left or right
for counter1 = 175 to 150 step -1
servopos Eyelr,counter1 
pause delay1
next counter1
pointer1 = 150
goto skipml1

ml1: for counter1 = 125 to 150 step 1
servopos Eyelr,counter1 
pause delay1
next counter1
pointer1 = 150

skipml1: pause 9000 'delay to look natural
goto move1 'return to move loop

left1: if pointer1 = 175 then move1 
if pointer1 = 125 then lmr1 
for counter1 = 150 to 175 step 1
servopos Eyelr,counter1 
pause delay1
next counter1
pointer1 = 175
goto skiplmr1

lmr1: for counter1 = 125 to 175 step 1
servopos Eyelr,counter1 
pause delay1
next counter1
pointer1 = 175

skiplmr1: pause 7000 'delay to look natural
goto move1 'return to move loop

start3: 'Eye Up/Down
let b24=153 'set pointer offset so that Eye Up/Down loop does not get stuck
let b22=150
let b23=150 'set default center values
servo Eyeud,pointer2 'center servo
pause 9500
for counter2 = 150 to 120 step -1 'move Eye from middle to up
servopos Eyeud,counter2
pause delay2
next counter2
pause 3000

for counter2 = 120 to 200 step 1
servopos Eyeud,counter2 'move Eye from up to down
pause delay2
next counter2
pause 3000

for counter2 = 200 to 150 step -1
servopos Eyeud,counter2 'move Eye from down to middle
pause delay2
next counter2
pause 4000

move2: random w11 'place a random number in wo (also B0 & B1)

if b23<120 then left2 'check for random up
if b23>=120 and b23<=150 then middle2 'check for random middle
if b23>=150 then right2 'check for random down
goto move2 'keep moving the Eye back to move loop

right2: if pointer2 = 120 then move2 'if Eye is already down goto back to move
if pointer2 = 150 then mr2 'check to see if Eye in pointed middle or up
for counter2 = 200 to 120 step -1 'move Eye from up to down
servopos Eyeud,counter2
pause delay2
next counter2
pointer2 = 120 'set Eye pointer direction to down
goto skipmr2

mr2: for counter2 = 150 to 120 step -1 'move Eye from middle to down
servopos Eyeud,counter2
pause delay2
next counter2
pointer2 = 120 'set Eye pointer direction to down

skipmr2: pause 7000 'delay to look natural
goto move2 'return to move loop

middle2: if pointer2 = 150 then move2 'if Eye is already in the middle then go back to move
if pointer2 = 120 then ml2 'check to see if head is pointed up or down
for counter2 = 200 to 150 step -1
servopos Eyeud,counter2 'move Eye from down to middle
pause delay2
next counter2
pointer2 = 150
goto skipml2

ml2: for counter2 = 120 to 150 step 1
servopos Eyeud,counter2 'move servo from left to middle
pause delay2
next counter2
pointer2 = 150

skipml2: pause 9000 'delay to look natural
goto move2 'return to move loop

left2: if pointer2 = 200 then move2 'if head is already left then return to move
if pointer2 = 120 then lmr2 'check if the head is in the middle or the right
for counter2 = 150 to 200 step 1
servopos Eyeud,counter2 'move head from middle to left
pause delay2
next counter2
pointer2 = 200
goto skiplmr2

lmr2: for counter2 = 120 to 200 step 1
servopos Eyeud,counter2 'move head from right to left
pause delay2
next counter2
pointer2 = 200

skiplmr2: pause 7000 'delay to look natural
goto move2 'return to move loop


----------



## Palmdale Haunter (Mar 3, 2012)

Cool!


----------

