Here is my script:
Code: Select all
import RPi.GPIO as GPIO
import time
halldetect = 0
timer = 0
GPIO.setmode(GPIO.BCM)
GPIO.setup(24,GPIO.IN, pull_up_down=GPIO.PUD_UP)
try:
while True:
hall = GPIO.input(24)
if timer < 1:
if not hall:
halldetect += 1
timer += 0.01
else:
halldetect = 0
timer = 0
print(halldetect)
time.sleep(0.01)
except KeyboardInterrupt:
GPIO.cleanup()