Created
February 8, 2016 18:42
-
-
Save waveform80/8564741f31978b43349f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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