Advertisement
gPiOBox

Beginner - Traffic Lights - Raspberry Pi

Oct 23rd, 2017
1,095
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. """
  2. filename:gpio_RPi_TrafficLights.py
  3. Beginner Project - Traffic Lights
  4. written by Trevor Olsson
  5. © GPIO Support Services LTD MMXVII
  6. More info here: http://www.gpio.co.uk/traffic-lights/
  7. and here: https://gpiozero.readthedocs.io/en/stable/api_boards.html
  8. """
  9.  
  10. from gpiozero import TrafficLights
  11. from time import sleep
  12. traffic = TrafficLights(17,18,27,initial_value=False) # Choose outputs to use and turn off at start
  13.  
  14. while True:
  15.     traffic.red.on()
  16.     sleep(2)
  17.     traffic.amber.on()
  18.     sleep(2)
  19.     traffic.red.off()
  20.     traffic.amber.off()
  21.     traffic.green.on()
  22.     sleep(2)
  23.     traffic.green.off()
  24.     traffic.amber.on()
  25.     sleep(2)
  26.     traffic.amber.off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement