a
This commit is contained in:
9
init.py
9
init.py
@@ -21,12 +21,14 @@ def isSunUp() -> bool:
|
||||
class AlarmClock:
|
||||
ledGpio: GPIO
|
||||
buttonGpio: GPIO
|
||||
relayGpio: GPIO
|
||||
lastKnownButtonState: bool = False
|
||||
lcd: JHD1802
|
||||
lastButtonPressTime: float = 0.0
|
||||
def __init__(self, pins: dict = {}):
|
||||
self.ledGpio = GPIO(pins.get("led", 5), GPIO.OUT)
|
||||
self.buttonGpio = GPIO(pins.get("button", 6), GPIO.IN)
|
||||
self.relayGpio = GPIO(pins.get("relay", 16), GPIO.OUT)
|
||||
self.lcd = JHD1802()
|
||||
self.setLcdText("AlarmClock Init")
|
||||
|
||||
@@ -40,12 +42,11 @@ class AlarmClock:
|
||||
currentButtonState = not self.buttonGpio.read()
|
||||
if currentButtonState != self.lastKnownButtonState:
|
||||
self.lastKnownButtonState = currentButtonState
|
||||
if currentButtonState:
|
||||
self.onButtonPress("button")
|
||||
self.onButtonPress("button", currentButtonState)
|
||||
|
||||
|
||||
def onButtonPress(self, button: str):
|
||||
print(f"Button {button} pressed")
|
||||
def onButtonPress(self, button: str, state: bool):
|
||||
print(f"Button '{button}' pressed state: {state}")
|
||||
if button == "button":
|
||||
self.lastButtonPressTime = time()
|
||||
self.setLcdText(self.lastButtonPressTime.__str__())
|
||||
|
||||
Reference in New Issue
Block a user