Home > RaspberryPi > Raspberry Pi Traffic Light

03/26/2023

Raspberry Pi Traffic Light

Writing about Raspberry Pi Traffic Light for educational and informational purposes only. however, do not hesitate to use this information on your own risk as we make no warranty of any kind.


Making Raspberry Pi Traffic Light.
This is a good example of how to switch on/off a GPIO


import RPi.GPIO as GPIO
import time

try:
  while True:
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BOARD)
    
    GPIO.setup(8, GPIO.OUT)
    GPIO.setup(10, GPIO.OUT)
    GPIO.setup(12, GPIO.OUT)
    
    GPIO.output(8, GPIO.LOW)
    GPIO.output(10, GPIO.LOW)
    GPIO.output(12, GPIO.HIGH)
    time.sleep(5)
    
    GPIO.output(8, GPIO.LOW)
    GPIO.output(10, GPIO.HIGH)
    GPIO.output(12, GPIO.LOW)
    time.sleep(1)
    
    GPIO.output(8, GPIO.HIGH)
    GPIO.output(10, GPIO.LOW)
    GPIO.output(12, GPIO.LOW)
    time.sleep(5)
    
except KeyboardInterrupt:
  p.stop()
  GPIO.cleanup()          

Raspberry Pi Traffic Light
All content and information on this web site is intended for educational and entertainment purposes only.