master
Nicolò Balzarotti 2023-01-05 15:49:33 +01:00
parent bd96ca95a6
commit 7cfbb3f56b
1 changed files with 5 additions and 7 deletions

View File

@ -28,15 +28,13 @@ class GPIOState(Sensor):
def __init__(self, pin, transform=lambda x: 1-x):
self.pin = pin
self.transform = transform
self.value = GPIO.input(self.pin)
self.update_time()
def update_time(self):
self.time = perf_counter()
def read(self):
self.value = GPIO.input(self.pin)
try:
self.value = GPIO.input(self.pin)
except:
self.value = None
self.time = perf_counter()
return (self.time, self.transform(self.value))