25 lines
No EOL
554 B
Python
25 lines
No EOL
554 B
Python
from src.variables.service import get_variable, set_variable
|
|
import RPi.GPIO as GPIO
|
|
import datetime
|
|
|
|
|
|
pin = 7
|
|
GPIO.setmode(GPIO.BOARD)
|
|
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
|
set_variable("speed_reader_last_impulse_time", datetime.datetime.now(), False)
|
|
|
|
|
|
def event(pin):
|
|
actual = datetime.datetime.now()
|
|
last = get_variable("speed_reader_last_impulse_time")
|
|
difference = (actual - last).total_seconds()
|
|
|
|
if difference != 0:
|
|
return
|
|
|
|
print(difference)
|
|
|
|
|
|
|
|
|
|
GPIO.add_event_detect(pin, GPIO.RISING, callback=event) |