pi_pico_lab/siwatlib/debounce.py

12 lines
442 B
Python
Raw Normal View History

2022-04-08 18:10:31 +00:00
from time import perf_counter as seconds
class debounce:
def __init__(self,state: bool, debounce_time: float) -> None:
self.last_pressed = seconds()
self.debounce_time = debounce_time
self.state = state
def set_state(self, state: bool) -> bool:
if seconds()-self.last_pressed > self.debounce_time:
self.state = state
return self.state
else:
return self.state