12 lines
442 B
Python
12 lines
442 B
Python
|
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
|