import machine
import time
import ssd1306
# Initialize the OLED display
i2c = machine.I2C(scl=machine.Pin(4), sda=machine.Pin(5))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
# Define the traffic light pins
red_light = machine.Pin(26, machine.Pin.OUT)
yellow_light = machine.Pin(25, machine.Pin.OUT)
green_light = machine.Pin(27, machine.Pin.OUT)
def traffic_light_sequence():
# Red light ON for 5 seconds
red_light.on()
for i in range(5, 0, -1):
oled.fill(0)
oled.text("Delay: {}s".format(i), 0, 0)
oled.show()
time.sleep(1)
red_light.off()
# Yellow light ON for 3 seconds
yellow_light.on()
for i in range(3, 0, -1):
oled.fill(0)
oled.text("Delay: {}s".format(i), 0, 0)
oled.show()
time.sleep(1)
yellow_light.off()
# Green light ON for 5 seconds
green_light.on()
for i in range(5, 0, -1):
oled.fill(0)
oled.text("Delay: {}s".format(i), 0, 0)
oled.show()
time.sleep(1)
green_light.off()
while True:
traffic_light_sequence()