User manual
37
Fig. 4.2: Traffic light with flashing light for pedestrians.
The programme ampel02.py controls the traffic light system. Compared to the previous version the program
has been slightly expanded.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
red = 0; yellow = 1; green = 2; blue = 3
Light=[4,18,23,24]
GPIO.setup(light[red], GPIO.OUT, initial=False)
GPIO.setup(light[yellow], GPIO.OUT, initial=False)
GPIO.setup(light[green], GPIO.OUT, initial=True)
GPIO.setup(light[blue], GPIO.OUT, initial=False)
print (“Ctrl+C exits the program")
try:
while True: