import machine import utime from machine import Pin # Ausgänge setzen LED_onboard = machine.Pin(25, machine.Pin.OUT) LED_RED = machine.Pin(0, machine.Pin.OUT) # Auslösung getriggert, warte auf Dunkelheit LED_GREEN = machine.Pin(1, machine.Pin.OUT) # Betriebsbereit LED_BLAU = machine.Pin(2, machine.Pin.OUT) # Ozongenerator läuft / blinkend: Wartezeit FAN = machine.Pin(16, machine.Pin.OUT) OZON = machine.Pin(17, machine.Pin.OUT) LIGHT = machine.Pin(10, machine.Pin.IN, machine.Pin.PULL_UP) SWITCH = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_UP) # alle Ausgänge auf Null setzen LED_RED.value(0) LED_GREEN.value(0) LED_BLAU.value(0) FAN.value(1) OZON.value(1) # Initialize a variable to track switch state switch_pressed = False # Initialize a variable to track ozone generator cooldown ozone_cooldown = 0 while True: print("ganz am Anfang") if not switch_pressed: # Check twilight switch and adjust the green LED accordingly if LIGHT.value() == 1: # It's dark, so turn on the green LED LED_GREEN.value(1) else: # It's bright, so turn off the green LED LED_GREEN.value(0) print("Press the switch to start") # Wait for the switch on pin 15 to be pressed while SWITCH.value() == 1: # Continuously check the twilight switch and adjust the green LED if LIGHT.value() == 1: LED_GREEN.value(1) else: LED_GREEN.value(0) print("Waiting for darkness") # Prevent the switch from being pressed again while the following tasks run switch_pressed = True # Turn on the Red LED, turn off the Green LED LED_RED.value(1) LED_GREEN.value(0) # Wait until it's dark while LIGHT.value() == 1: pass if ozone_cooldown <= 0: # Fan should be activated for 10 seconds FAN.value(0) utime.sleep(3) # pre-roll time fan # Start the ozone generator 2 seconds after the fans start OZON.value(0) LED_BLAU.value(1) utime.sleep(3) # ozone time OZON.value(1) LED_BLAU.value(0) utime.sleep(5) # post-roll time fan FAN.value(1) # Set the ozone cooldown period to 2 minutes (120 seconds) ozone_cooldown = 180 #3minuten # All LEDs off LED_RED.value(0) LED_GREEN.value(0) # Allow the switch to be pressed again switch_pressed = False # Countdown the ozone cooldown and print remaining time while ozone_cooldown > 0: mins = ozone_cooldown // 60 secs = ozone_cooldown % 60 print("Ozone generator cooldown: {:02d}:{:02d}".format(mins, secs)) LED_RED.value(0) utime.sleep(1) LED_RED.value(1) ozone_cooldown -= 1 # Reset the switch_pressed flag after the ozone cooldown switch_pressed = False LED_RED.value(0) print("Ende erreicht")