Instructables

WowWee's Elvis Alive to The Elivinator Project

FeaturedContest Winner

Step 28: Moving the eyes with a Basic Stamp



Now let's look at another video of making the eyes move with a Basic Stamp 2
Here is the code dor the routine.

' {$STAMP BS2}
' {$PBASIC 2.5}
' test motor movement and check vr's for proper poition and move eyes rt and lt
Result VAR Word 'Word variable to hold result.
LOW 10 ' set pin 10 low eye right
HIGH 8 ' set pin 8 high eye left to move motor eye left
LOW 8 ' ser pin 8 low eye left to stop motor eye left
pwmduty VAR Byte
pwmout PIN 6 'LED connected to P6
pwmduty=0 'set duty cycle to 0

Main:
GOSUB checkeyes
IF RESULT =1 OR RESULT =0 THEN GOTO BUG ' if vr has no signal stop program
IF result <= 1100 THEN GOTO EYELEFT
IF result >= 2300 THEN GOTO eyeright
GOTO eyeright
GOTO MAIN

BUG:
DEBUG "bug found in VR READINGS = ", DEC RESULT,CR ' if signal loss stop routine
STOP

checkeyes: ' checking the VR location

HIGH 7 'use pin 7 to Discharge the cap circuit
PAUSE 1 'for 1 ms.
RCTIME 7, 1, Result 'Measure RC charge time. convert analog to digital

RETURN

eyeright: ' move right eye to the right
HIGH 10 ' turn motor on

CHECKRT:
DEBUG "eye right mode", DEC result, CR
GOSUB checkeyes
IF Result < 1100 THEN GOTO LINESLOW 'check to see if it at the lower limits

GOTO CHECKRT

eyeleft: 'move eye to the left

HIGH 8 'turn on motor

CHECKLT:
DEBUG "eyeleft mode", DEC result

GOSUB checkeyes
IF Result > 2300 THEN GOTO LinesLow ' if over limit turn off motor

GOTO CHECKLT

LinesLow: ' turn off motor
LOW 8
LOW 10
DEBUG "droped lines low" , CR
GOSUB runhigh

GOTO main

runhigh:
DO WHILE pwmduty<255 'keep increasing dutycycle till 255 is reached
PWM PWMout, pwmduty,15 ' run to increase voltage to LED decrease last # for faster
pwmduty=pwmduty+1 'Increase duty cycle by 1
LOOP

runlow:
IF pwmduty>=255 THEN pwmduty=254 'set duty cycle to 254
DO WHILE pwmduty >=1 'continue to decrease voltage to LED
PWM pwmout,pwmduty,25 ' run to decrease voltage to LED increase last # for faster
pwmduty=pwmduty-1 'Decrease cycle by 1
LOOP
PAUSE 2000

RETURN

 
Remove these adsRemove these ads by Signing Up
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!