TCS2FHEM/Keypad.py

27 lines
973 B
Python
Raw Normal View History

2022-12-18 16:23:23 +01:00
from machine import Pin
import utime as time
debounce_time = 0
class Keypad():
def __init__(self):
2023-01-05 18:23:40 +01:00
self.taste1 = Pin(20, Pin.IN, Pin.PULL_UP)
self.taste2 = Pin(21, Pin.IN, Pin.PULL_UP)
self.taste3 = Pin(18, Pin.IN, Pin.PULL_UP)
self.taste4 = Pin(19, Pin.IN, Pin.PULL_UP)
2022-12-18 16:23:23 +01:00
self.taste1.irq(trigger=Pin.IRQ_FALLING, handler=self.callback)
self.taste2.irq(trigger=Pin.IRQ_FALLING, handler=self.callback)
self.taste3.irq(trigger=Pin.IRQ_FALLING, handler=self.callback)
self.taste4.irq(trigger=Pin.IRQ_FALLING, handler=self.callback)
self.interrupt_flag = 0
self.tastePressed = self.taste1
# Keypress and debouncing
def callback(self, pin):
global debounce_time
if (time.ticks_ms() - debounce_time) > 300:
self.interrupt_flag = 1
debounce_time = time.ticks_ms()
self.tastePressed = pin