# Exercice 3 - Version 4 - Correction 2
from machine import Pin
from time import sleep

led = Pin(32, Pin.OUT)
btn = Pin(21, Pin.IN)

# Liste des diodes utilisées
leds = [Pin(32, Pin.OUT), Pin(33, Pin.OUT), Pin(25, Pin.OUT)]
tmps = [3, 1, 3]
# mode veille
suspended = False
tm = 0
idx = 2
while True:
  et = btn.value()
  if et:
    suspended = not suspended
    idx = 2
    tm = 0
    for i in range(3):
      leds[i].off()
  
  if not suspended:
    if tm == 0:
      leds[idx].off()
      idx = (idx + 1) % 3
      leds[idx].on()
      tm = tmps[idx] // 0.01
    else:
      tm -= 1
  else:
    if tm == 0:
      leds[1].value(not leds[1].value())
      tm = tmps[1] // 0.01
    else:
      tm -= 1
  sleep(0.01)