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