from machine import Pin
import time
# LED pinnen
LED_R = 15
LED_O = 2
LED_G = 4
led_R = Pin(LED_R, Pin.OUT)
led_O = Pin(LED_O, Pin.OUT)
led_G = Pin(LED_G, Pin.OUT)
# LED structuur:
# [pin, status, laatste_tijd, on_time, off_time]
leds = [
# pin state last_time ON OFF (ms)
[led_R, False, time.ticks_ms(), 1000, 4000], # rood
[led_O, False, time.ticks_ms(), 500, 1500], # oranje
[led_G, False, time.ticks_ms(), 3000, 2000] # groen
]
def update_led(led):
pin, state, last_time, on_time, off_time = led
current_time = time.ticks_ms()
if state: # LED is AAN
if time.ticks_diff(current_time, last_time) >= on_time:
pin.off()
led[1] = False
led[2] = current_time
else: # LED is UIT
if time.ticks_diff(current_time, last_time) >= off_time:
pin.on()
led[1] = True
led[2] = current_time
while True:
for led in leds:
update_led(led)
time.sleep_ms(10) # CPU rust