Advertisement
belrey10

1 – Traffic Light Simulator

Nov 5th, 2024 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import machine
  2. import utime
  3.  
  4. # Initialize GPIO pins for LEDs
  5. red_led = machine.Pin(16, machine.Pin.OUT)
  6. yellow_led = machine.Pin(17, machine.Pin.OUT)
  7. green_led = machine.Pin(18, machine.Pin.OUT)
  8.  
  9. # Function to turn all LEDs off
  10. def all_off():
  11.     red_led.value(0)
  12.     yellow_led.value(0)
  13.     green_led.value(0)
  14.  
  15. # Main Loop
  16. while True:
  17.     all_off()  # Turn all LEDs off
  18.    
  19.     red_led.value(1)  # Turn red LED on
  20.     utime.sleep(5)  # Wait for 5 seconds
  21.    
  22.     all_off()  # Turn all LEDs off
  23.    
  24.     yellow_led.value(1)  # Turn yellow LED on
  25.     utime.sleep(1)  # Wait for 1 second
  26.    
  27.     all_off()  # Turn all LEDs off
  28.    
  29.     green_led.value(1)  # Turn green LED on
  30.     utime.sleep(4)  # Wait for 4 seconds
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement