{{ ************************************ * demo_servo32_controlled * * 2008 Michael St.Onge * ************************************ 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)