-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknightrider.py
55 lines (45 loc) · 1.11 KB
/
knightrider.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from BlinkyTape import BlinkyTape
import urllib2
import re
from time import sleep
import random
import math
bb = BlinkyTape('/dev/ttyACM0') #least on Mac OS X, this is the port to use!
OFF_COLOUR = [0,0,0]
DISPLAY_COLOUR = [254,0,0]
R_INTERVAL = DISPLAY_COLOUR[0]/15
G_INTERVAL = DISPLAY_COLOUR[1]/15
B_INTERVAL = DISPLAY_COLOUR[2]/15
DISPLAY_LENGTH = 60
UPDATE_INTERVAL = 0.02
pixels=[OFF_COLOUR for i in range(DISPLAY_LENGTH)]
def fadePixel(pixel):
if pixel[0] != 0:
pixel[0] = pixel[0] - R_INTERVAL
if pixel[0] < 0:
pixel[0] = 0
if pixel[1] != 0:
pixel[1] = pixel[1] - G_INTERVAL
if pixel[1] < 0:
pixel[1] = 0
if pixel[2] != 0:
pixel[2] = pixel[2] - B_INTERVAL
if pixel[2] < 0:
pixel[2] = 0
def fadePixels():
for x in range(len(pixels)):
fadePixel(pixels[x])
def knightrider():
for i in range(DISPLAY_LENGTH):
fadePixels()
pixels[i] = list(DISPLAY_COLOUR)
bb.send_list(pixels)
sleep(UPDATE_INTERVAL)
for i in reversed(range(DISPLAY_LENGTH)):
fadePixels()
pixels[i] = list(DISPLAY_COLOUR)
bb.send_list(pixels)
sleep(UPDATE_INTERVAL)
bb.displayColor(0,0,0)
while True:
knightrider()