Last active
November 13, 2016 18:22
-
-
Save marcellodesales/ae2f51c6df5215fa5c1c368ef8340dca to your computer and use it in GitHub Desktop.
The way to implement a night rider loop like https://www.youtube.com/watch?time_continue=4&v=KY1kvakZ1cU - PiLiter https://shop.pimoroni.com/products/pi-liter-8-led-strip-for-the-raspberry-pi. See it running at https://repl.it/EWjf/0
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 time import sleep | |
leds = [11, 14, 35, 67, 78, 89] | |
forward = range(len(leds)) | |
backward = list(reversed(forward)) | |
print forward | |
print backward | |
loop = 3 | |
sleepTime = 0.08 | |
while loop > 0: | |
print "on(" + str(leds[0]) + ")" | |
sleep(sleepTime) | |
for i in forward: | |
first = i | |
second = i if i + 1 == len(forward) else i + 1 | |
if (first == second): | |
continue | |
print "# " + str(first) + ":" + str(second) | |
print "off(" + str(leds[first]) + ") - on(" + str(leds[second]) + ")" | |
sleep(sleepTime) | |
for j in backward: | |
second = j | |
first = j if j + 1 == len(backward) else j + 1 | |
if (first == second) or (second == 0): | |
continue | |
print "# " + str(first) + ":" + str(second) | |
print "off(" + str(leds[first]) + ") - on(" + str(leds[second]) + ")" | |
sleep(sleepTime) | |
print "off(" + str(leds[1]) + ")" | |
loop = loop -1 |
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
$ python leds.py | |
[0, 1, 2, 3, 4, 5] | |
[5, 4, 3, 2, 1, 0] | |
on(11) | |
# 0:1 | |
off(11) - on(14) | |
# 1:2 | |
off(14) - on(35) | |
# 2:3 | |
off(35) - on(67) | |
# 3:4 | |
off(67) - on(78) | |
# 4:5 | |
off(78) - on(89) | |
# 5:4 | |
off(89) - on(78) | |
# 4:3 | |
off(78) - on(67) | |
# 3:2 | |
off(67) - on(35) | |
# 2:1 | |
off(35) - on(14) | |
off(14) | |
on(11) | |
# 0:1 | |
off(11) - on(14) | |
# 1:2 | |
off(14) - on(35) | |
# 2:3 | |
off(35) - on(67) | |
# 3:4 | |
off(67) - on(78) | |
# 4:5 | |
off(78) - on(89) | |
# 5:4 | |
off(89) - on(78) | |
# 4:3 | |
off(78) - on(67) | |
# 3:2 | |
off(67) - on(35) | |
# 2:1 | |
off(35) - on(14) | |
off(14) | |
on(11) | |
# 0:1 | |
off(11) - on(14) | |
# 1:2 | |
off(14) - on(35) | |
# 2:3 | |
off(35) - on(67) | |
from time import sleep | |
# 3:4 | |
off(67) - on(78) | |
# 4:5 | |
off(78) - on(89) | |
# 5:4 | |
off(89) - on(78) | |
# 4:3 | |
off(78) - on(67) | |
# 3:2 | |
off(67) - on(35) | |
# 2:1 | |
off(35) - on(14) | |
off(14) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment