Traffic light
Traffic Light
code
main.py
from machine import Pin as Pinkeo
import time
green1 = Pinkeo(0, Pinkeo.OUT)
yellow1 = Pinkeo(1, Pinkeo.OUT)
red1 = Pinkeo(2, Pinkeo.OUT)
green2 = Pinkeo(22, Pinkeo.OUT)
yellow2 = Pinkeo(26, Pinkeo.OUT)
red2 = Pinkeo(27, Pinkeo.OUT)
green4 = Pinkeo(11, Pinkeo.OUT)
yellow4 = Pinkeo(12, Pinkeo.OUT)
red4 = Pinkeo(13, Pinkeo.OUT)
green3 = Pinkeo(19, Pinkeo.OUT)
yellow3 = Pinkeo(20, Pinkeo.OUT)
red3 = Pinkeo(21, Pinkeo.OUT)
i = 0
while i <= 40:
time.sleep(1)
i += 1
if i < 7:
green1.on()
yellow1.off()
red1.off()
green2.off()
yellow2.off()
red2.on()
green3.off()
yellow3.off()
red3.on()
green4.off()
yellow4.off()
red4.on()
elif i < 10:
green1.off()
yellow1.on()
red1.off()
red2.on()
yellow2.off()
green2.off()
red3.on()
yellow3.off()
green3.off()
red4.on()
yellow4.off()
green4.off()
elif i < 17:
red1.on()
yellow1.off()
green1.off()
red2.off()
yellow2.off()
green2.on()
red3.on()
yellow3.off()
green3.off()
red4.on()
yellow4.off()
green4.off()
elif i < 20:
red1.on()
yellow1.off()
green1.off()
red2.off()
yellow2.on()
green2.off()
red3.on()
yellow3.off()
green3.off()
red4.on()
yellow4.off()
green4.off()
elif i < 27:
red1.on()
yellow1.off()
green1.off()
red2.on()
yellow2.off()
green2.off()
red3.off()
yellow3.off()
green3.on()
red4.on()
yellow4.off()
green4.off()
elif i < 30:
red1.on()
yellow1.off()
green1.off()
red2.on()
yellow2.off()
green2.off()
red3.off()
yellow3.on()
green3.off()
red4.on()
yellow4.off()
green4.off()
elif i < 37:
red1.on()
yellow1.off()
green1.off()
red2.on()
yellow2.off()
green2.off()
red3.on()
yellow3.off()
green3.off()
red4.off()
yellow4.off()
green4.on()
elif i < 40:
red1.on()
yellow1.off()
green1.off()
red2.on()
yellow2.off()
green2.off()
red3.on()
yellow3.off()
green3.off()
red4.off()
yellow4.on()
green4.off()
print(i)
diagram.json
{
"version": 1,
"editor": "wokwi",
"parts": [
{
"type": "wokwi-pi-pico",
"id": "pico",
"top": -86.34,
"left": 62.03,
"attrs": { "env": "micropython-20220618-v1.19.1" }
},
{
"type": "wokwi-led",
"id": "led1",
"top": -123.41,
"left": 163.29,
"attrs": { "color": "red" }
},
{
"type": "wokwi-led",
"id": "led2",
"top": -126.89,
"left": 203.83,
"attrs": { "color": "yellow" }
},
{
"type": "wokwi-led",
"id": "led3",
"top": -124.74,
"left": 244.67,
"attrs": { "color": "limegreen" }
},
{
"type": "wokwi-led",
"id": "led4",
"top": -132.44,
"left": -120.79,
"attrs": { "color": "red" }
},
{
"type": "wokwi-led",
"id": "led5",
"top": 12.32,
"left": 305.78,
"attrs": { "color": "red" }
},
{
"type": "wokwi-led",
"id": "led6",
"top": 31.09,
"left": -83.8,
"attrs": { "color": "red" }
},
{
"type": "wokwi-led",
"id": "led8",
"top": -132.86,
"left": -75.86,
"attrs": { "color": "yellow" }
},
{
"type": "wokwi-led",
"id": "led9",
"top": 7.92,
"left": 337.33,
"attrs": { "color": "yellow" }
},
{
"type": "wokwi-led",
"id": "led10",
"top": 29.73,
"left": -42.45,
"attrs": { "color": "yellow" }
},
{
"type": "wokwi-led",
"id": "led7",
"top": -131.64,
"left": -23.77,
"attrs": { "color": "limegreen" }
},
{
"type": "wokwi-led",
"id": "led11",
"top": 9.96,
"left": 369.97,
"attrs": { "color": "limegreen" }
},
{
"type": "wokwi-led",
"id": "led12",
"top": 31.05,
"left": -8.72,
"attrs": { "color": "limegreen" }
}
],
"connections": [
[ "led1:C", "pico:GND.8", "gray", [ "v0" ] ],
[ "led7:A", "pico:GP0", "green", [ "v0" ] ],
[ "led8:A", "pico:GP1", "yellow", [ "v0" ] ],
[ "led4:C", "pico:GND.1", "gray", [ "v0" ] ],
[ "led8:C", "pico:GND.1", "gray", [ "v0" ] ],
[ "led7:C", "pico:GND.1", "gray", [ "v0" ] ],
[ "led2:C", "pico:GND.8", "gray", [ "v0" ] ],
[ "led3:C", "pico:GND.8", "gray", [ "v0" ] ],
[ "led12:C", "pico:GND.4", "gray", [ "v0" ] ],
[ "led10:C", "pico:GND.4", "gray", [ "v0" ] ],
[ "led6:C", "pico:GND.4", "gray", [ "v0" ] ],
[ "led12:A", "pico:GP11", "green", [ "v0" ] ],
[ "led10:A", "pico:GP12", "yellow", [ "v0" ] ],
[ "led6:A", "pico:GP13", "red", [ "v0" ] ],
[ "led1:A", "pico:GP27", "red", [ "v0" ] ],
[ "led2:A", "pico:GP26", "gold", [ "v0" ] ],
[ "led3:A", "pico:GP22", "green", [ "v0" ] ],
[ "led5:C", "pico:GND.5", "gray", [ "v0" ] ],
[ "led9:C", "pico:GND.5", "gray", [ "v0" ] ],
[ "led11:C", "pico:GND.5", "gray", [ "v0" ] ],
[ "led5:A", "pico:GP21", "red", [ "v0" ] ],
[ "led9:A", "pico:GP20", "gold", [ "v0" ] ],
[ "led11:A", "pico:GP19", "green", [ "v0" ] ],
[ "pico:GP2", "led4:A", "red", [ "h0" ] ]
],
"dependencies": {}
}
