Skip to content

Instantly share code, notes, and snippets.

@waveform80
Created February 8, 2016 18:42
Show Gist options
  • Save waveform80/8564741f31978b43349f to your computer and use it in GitHub Desktop.
Save waveform80/8564741f31978b43349f to your computer and use it in GitHub Desktop.
from gpiozero import TrafficLights
from time import sleep
from itertools import cycle, chain
from signal import pause
lights = TrafficLights(12, 16, 19, pwm=True)
def slow(gen):
for item in gen:
yield item
sleep(0.01)
def pulse():
ramp = [i / 10 for i in range(10)]
return cycle(chain(ramp, reversed(ramp)))
lights.red.source = slow(lights.green.values)
lights.amber.source = slow(lights.green.values)
lights.green.source = slow(pulse())
pause()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment