import time
from button import Button
from alarm_timer import AlarmTimer
from led import Led
#Init of all components
on_led = Led(10,1)
cooling_led = Led (15,1)
cooling_on_button = Button(16)
timer_on_button = Button(22)
alarm_timer = AlarmTimer(10000)
#power supply led on
on_led.on()
#device control
while True:
#cooling functionality
if cooling_on_button.is_pressed() and cooling_led.get_led_state()!=1:
cooling_led.on()
#print("device on")
elif cooling_on_button.is_pressed() and (cooling_led.get_led_state()==1 or alarm_timer.get_timer_running()):
cooling_led.off()
#print("device off")
elif cooling_led.get_led_state()==1 and alarm_timer.get_timer_running():
cooling_led.off()
cooling_led.blink()
#print("timer on")
#timer functionality
if cooling_led.get_led_state()==1 and timer_on_button.is_pressed() and not alarm_timer.get_timer_running():
alarm_timer.start()
#print("timer started")
elif timer_on_button.is_pressed() and alarm_timer.get_timer_running():
alarm_timer.stop()
cooling_led.on()
#print("timer stopped")
elif alarm_timer.get_alarm_active():
cooling_led.off()
alarm_timer.stop()
#print("timer finished")
time.sleep(0.15)