from machine import Pin, ADC
import time
# Définition des broches
LED_ROUGE = Pin(5, Pin.OUT)
LED_JAUNE = Pin(2, Pin.OUT)
LED_VERTE = Pin(4, Pin.OUT)
pot = ADC(Pin(34))
pot.atten(ADC.ATTN_11DB) # plage 0–3.3V
while True:
# Lire le potentiomètre (0 à 4095)
valeurPot = pot.read()
# Durée du feu vert : 5 à 20 secondes
dureeVert = int(5 + (valeurPot / 4095) * 15)
print("Valeur trafic :", valeurPot,
"| Duree feu vert :", dureeVert, "s")
# 🔴 ROUGE
LED_ROUGE.on()
LED_JAUNE.off()
LED_VERTE.off()
time.sleep(5)
# 🟢 VERT
LED_ROUGE.off()
LED_JAUNE.off()
LED_VERTE.on()
time.sleep(dureeVert)
# 🟡 JAUNE
LED_ROUGE.off()
LED_JAUNE.on()
LED_VERTE.off()
time.sleep(2)