I am working on a project that I need to keep a running total of how many times the output was signaled. I cannot figure out how to perform the operators to keep count. I need help with figuring out the code to write on if GPOI 13 is True then ass 1 to total and if GPIO 15 is True then subtract from total. And print the total
import RPi.GPIO as GPIO import time import itertools GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.IN) #PIR POOL MOTION GPIO.setup(13, GPIO.IN) #PIR GATE 1 SENSOR GPIO.setup(15, GPIO.IN) #PIR GATE 2 SENSOR GPIO.setup(36, GPIO.OUT) #LED POOL MOTION GPIO.setup(38, GPIO.OUT) #LED GATE 1 SENSOR GPIO.setup(40, GPIO.OUT) #LED GATE 2 SENSOR counter = 0 try: time.sleep(2) # to stabilize sensor while True: if GPIO.input(11): GPIO.output(36, True) print ("DETECTED3") time.sleep(2) #to avoid multiple detection GPIO.output(36, False) if GPIO.input(13): counter = 0 counter +=1 print ("1+") GPIO.output(38, True) print ("DETECTED2") time.sleep(2) #to avoid multiple detection GPIO.output(38, False) if GPIO.input(15): GPIO.output(40, True) print ("DETECTED1") time.sleep(2) #to avoid multiple detection GPIO.output(40, False) else: print ("Not detected") time.sleep(2) #loop delay, should be less than detection delay except: GPIO.cleanup()
buran write Mar-05-2021, 02:10 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.