Sensor and servo
bboy8012
Posts: 153
I'm using a PIR sensor and servo, my problem is when I load the prop it everything is fine, but when it first detects motion it does what its supposed to, but after the servo keeps repeating the servo ramp.
I have testeted the servo ramping code by itself and it works fine, with the finite loop of 2, its when I add the PIR sensor it gets all whacky.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PUB detectAnimal | smPos 'servo.Set(pServo, 1500) 'Setting servo to center postion 'repeat ' Repeat if ina[noparse][[/noparse]pirSen] == 1 ' If PIN1 equals a 1 (PIR is triggered) !outa[noparse][[/noparse]detLed] ' Toggle PIN16 (LED on) waitcnt(clkfreq/10 + cnt) ' Wait a 10th of a second !outa[noparse][[/noparse]detLed] repeat 2 repeat smPos from 1200 to 1700 step 20 servo.Set(pServo, smPos) 'Move servo to servoPos postion 'pwm.Duty(pump,50,16665) 'Create a 60Hz 50% duty cycle waitcnt(clkfreq/1000 * 20 + cnt) '20ms synchronized delay repeat smPos from 1700 to 1200 step 20 servo.Set(pServo, smPos) 'Move servo to servoPos postion 'pwm.Duty(pump,50,16665) 'Create a 60Hz 50% duty cycle waitcnt(clkfreq/1000 * 20 + cnt) '20ms synchronized delay
I have testeted the servo ramping code by itself and it works fine, with the finite loop of 2, its when I add the PIR sensor it gets all whacky.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Comments
The other thing of interest is, if you have commented out the first repeat, then how is the cog staying alive at all after it hits bottom of the repeat2? You must loop the entire code to keep things running, else the servo outputs are floating around.
Post Edited (Todd Chapman) : 5/16/2010 7:15:11 PM GMT