Servo32 Object Controlled

Goal: Make an servo rotate to a desired position by pushing the right or left button.

Purpose: This will demonstrate the use of the “servo32″ object by Parallax, and demonstrate counting.

Clock frequency: 5,000 Hz

Propeller code type: This propeller code is based on spin language, and uses the “servo32″ object.

Files to download: (right click)

demo_servo32_controlled

servo32v3

Pics to Download: (click to enlarge)

Note: Only copy and paste from the link above, or formatting issues will occur!

{{
************************************
*      demo_servo32_controlled     *
*       2008                       *
************************************

Goal: Make an servo rotate to a desired position by pushing the right or
left button.

Purpose: This will demonstrate the use of the "servo32" object by Parallax,
and demonstrate counting.
}}

CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000                'Note Clock Speed for your setup!!

pinServo    = 0                     'Servo pin number
LeftButton  = 15
RightButton = 16
LeftLED     = 10
RightLED    = 21
VAR
word    x

OBJ
SERVO : "Servo32v3"

PUB Servo32_DEMO | temp

x := 1500                           'Center the servo
dira[LeftLED]~~                     'Set pin to output
dira[RightLED]~~                    'Set pin to output
SERVO.Start                         'Start Servo handler

repeat
SERVO.Set(pinServo,x)               'Output servo location to "Servo32v3" object
(position muse be between the range of 1000 to 2000)
outa[LeftLED]~                      'Turn off the LeftLED
outa[RightLED]~                     'Turn off the RightLED

if x > 2000
outa[LeftLED]~~                'Turn on the LeftLED if x is at the far left stop

if x < 1000
outa[RightLED]~~               'Turn on the RightLED if x is at the far right stop

if (ina[LeftButton] == 1) AND (x =< 2000)  'If left pushbutton pressed and x is
less than or equal to 2000
x += 1                                   '(Same as writing x := x + 1)

if (ina[RightButton] == 1) AND (x => 1000) 'If right pushbutton pressed and x is
greater than or equal to 1000
x -= 1                                   '(Same as writing x := x - 1)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>