Skip to content

Instantly share code, notes, and snippets.

@marcellodesales
Last active November 13, 2016 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcellodesales/ae2f51c6df5215fa5c1c368ef8340dca to your computer and use it in GitHub Desktop.
Save marcellodesales/ae2f51c6df5215fa5c1c368ef8340dca to your computer and use it in GitHub Desktop.
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
$ 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