but now
i need some help with my photogate code, the code work good but it has one defect, the time start once the program starts running but i need time to start when the photogate signal gets cut off, i would appreciate it if someone could help me out
Code: Select all
import RPi.GPIO as GPIO
import pigpio
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.IN)
servos = [27,22]
gpio = pigpio.pi()
start = time.time()
stop = time.time()
gateState = False
try:
while True:
if (GPIO.input(11) != gateState):
gateState = not gateState
if (gateState == True):
start = time.time()
else:
stop = time.time()
if stop - start > 0.01:
print "Time: ", stop - start, "s"
if stop - start < 2 :
gpio.set_servo_pulsewidth(servos[0], 1600)
time.sleep(1)
gpio.set_servo_pulsewidth(servos[0], 2250)
time.sleep(1)
if 2 < stop - start < 5:
gpio.set_servo_pulsewidth(servos[1], 1650)
time.sleep(1)
gpio.set_servo_pulsewidth(servos[1], 2250)
time.sleep(1)
if stop - start > 5 :
time.sleep(1)
except KeyboardInterrupt:
gpio.stop()
GPIO.cleanup()