diff --git a/init.py b/init.py index 23f200b..58b319e 100644 --- a/init.py +++ b/init.py @@ -1,9 +1,59 @@ -from astral import Astral +from time import time +from astral import LocationInfo +from astral.sun import sun +from datetime import date + +from grove.gpio import GPIO + +city = LocationInfo("Seinäjoki", "Finland", "Europe/Helsinki", 62.7900, 22.8400) +s = sun(city.observer, date=date.today()) +print(f"City: {city.name}, {city.region}") +print(f"Timezone: {city.timezone}") +print(f"Latitude: {city.latitude:.6f}; Longitude: {city.longitude:.6f}") + +def isSunUp() -> bool: + from datetime import datetime + now = datetime.now(city.tzinfo) + return s["sunrise"] <= now <= s["sunset"] + +# sunset and sunrise +class AlarmClock: + ledGpio: GPIO + buttonGpio: GPIO + lastKnownButtonState: bool = False + def __init__(self, pins: dict = {}): + self.ledGpio = GPIO(pins.get("led", 5), GPIO.OUT) + self.buttonGpio = GPIO(pins.get("button", 6), GPIO.IN) + + def loop(self): + while True: + currentButtonState = self.buttonGpio.read() + if currentButtonState != self.lastKnownButtonState: + self.lastKnownButtonState = currentButtonState + if currentButtonState: + self.onButtonPress("button") + time.sleep(0.05) + + def onButtonPress(self, button: str): + print(f"Button {button} pressed") + + def setLcdText(self, text: str): + print(f"LCD: {text}") + + + + + + +if __name__ == "__main__": + pins = { + "button": 6, + "led": 5, + "buzzer": 12, + } + alarm_clock = AlarmClock(pins) + + -CITY_NAME = "Seinäjoki" -a = Astral() -city = a[CITY_NAME] -print(f"Sunrise in {CITY_NAME}: {city.sunrise()}") -print(f"Sunset in {CITY_NAME}: {city.sunset()}")