# Copyright 2025 Frederik Tuczek
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from machine import I2C, Pin
from time import sleep
import time
import ds1307
import config
#Get Dates from separate config.py file. You can modify the file and restart the simulation.
kalender = config.kalender
#Configure connection to RTC
i2c = I2C(0, scl=Pin(13), sda=Pin(12))
rtc = ds1307.DS1307(i2c)
##code to initially set date on rtc https://randomnerdtutorials.com/raspberry-pi-pico-ds1307-rtc-micropython/
#initial_time_tuple = time.localtime()
#print(initial_time_tuple)
#initial_time_seconds = time.mktime(initial_time_tuple)
#print (initial_time_seconds)
#initial_time = ds1307.seconds2tuple(initial_time_seconds)
#print (initial_time)
#rtc.datetime(initial_time)
#Configure LEDs
LedG=Pin(6, Pin.OUT)
LedB=Pin(7, Pin.OUT)
LedS=Pin(8, Pin.OUT)
LedY=Pin(9, Pin.OUT)
##Check LEDs
LedG.low()
LedB.low()
LedS.low()
LedY.low()
#"Boot sequence" to ensure, all LEDs work properly
LedG.high()
sleep(0.3)
LedB.high()
sleep(0.3)
LedS.high()
sleep(0.3)
LedY.high()
sleep(0.3)
##check every 10000 seconds, if the LEDs have to be refreshed. Afterwards go to sleep.
while True:
LedG.low()
LedB.low()
LedS.low()
LedY.low()
currenttime=str(rtc.datetime().year)+'-'+('0'+str(rtc.datetime().month))[-2:]+'-'+('0'+str(rtc.datetime().day))[-2:]
print (currenttime)
for i in kalender:
if i[:10]==currenttime:
if i[-1:]=='G':
LedG.high()
if i[-1:]=='B':
LedB.high()
if i[-1:]=='S':
LedS.high()
if i[-1:]=='Y':
LedY.high()
sleep(10000)