Description
Write a python program to control a red, yellow and green led to display the pattern of a traffic light. The example code below can be dramatically improved using methods.

An addition to the project would include building a cardboard structure that looks like a stop light.
Level
Medium
Related Tags
Owned By
fmorton@Neighborhood Makers
Videos
Images
Copyright Notes
Source Code
from ptpma.components import PMALed
from time import sleep

led_red = PMALed("D0")
led_yellow = PMALed("D1")
led_green = PMALed("D2")

while True:
    led_red.on()
    led_yellow.off()
    led_green.off()
    sleep(5)

    led_red.off()
    led_yellow.on()
    led_green.off()
    sleep(2)

    led_red.off()
    led_yellow.off()
    led_green.on()
    sleep(5)