bboy8012
05-17-2010, 12:19 AM
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.
PUB detectAnimal | smPos
'servo.Set(pServo, 1500) 'Setting servo to center postion
'repeat ' Repeat
if ina[pirSen] == 1 ' If PIN1 equals a 1 (PIR is triggered)
!outa[detLed] ' Toggle PIN16 (LED on)
waitcnt(clkfreq/10 + cnt) ' Wait a 10th of a second
!outa[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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PUB detectAnimal | smPos
'servo.Set(pServo, 1500) 'Setting servo to center postion
'repeat ' Repeat
if ina[pirSen] == 1 ' If PIN1 equals a 1 (PIR is triggered)
!outa[detLed] ' Toggle PIN16 (LED on)
waitcnt(clkfreq/10 + cnt) ' Wait a 10th of a second
!outa[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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔