User Tools

Site Tools


traffic_light_leds_using_array

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
traffic_light_leds_using_array [2026/07/07 19:48] – [Introduction] walkeradmintraffic_light_leds_using_array [2026/07/07 19:48] (current) – [Introduction] walkeradmin
Line 72: Line 72:
 ---- ----
  
- 
- 
-<code:python | download> 
-#Traffic light LEDs using an array 
- 
-from machine import Pin 
-import time 
- 
-# Define GPIO pins for the LEDs 
-RED = Pin(2, Pin.OUT) 
-AMBER = Pin(6, Pin.OUT) 
-GREEN = Pin(10, Pin.OUT) 
- 
-# Put them in an array 
-lights = [RED, AMBER, GREEN] 
- 
-# Helper function to turn all lights off 
-def all_off(): 
-    for light in lights: 
-        light.off() 
- 
-while True: 
-    # Red 
-    all_off() 
-    RED.on() 
-    time.sleep(3) 
- 
-    # Red + Amber 
-    AMBER.on() 
-    time.sleep(1) 
- 
-    # Green 
-    all_off() 
-    GREEN.on() 
-    time.sleep(3) 
- 
-    # Amber 
-    all_off() 
-    AMBER.on() 
-    time.sleep(1) 
- 
-</code> 
traffic_light_leds_using_array.1783453703.txt.gz · Last modified: by walkeradmin