-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdna.py
63 lines (51 loc) · 1.94 KB
/
dna.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
56
57
58
59
60
61
62
63
#dna.py York Hackspace April 2014
#DNA (and sine wave) animation for SpaceHack game
#using 8x8 LED matrix controlled by Max7219 controller chip
#Play with the increment, delay and letter gap params
#to get the animation effect the way you like it
#For a pure sine wave set showdna to False
import LedControl
from math import sin, pi, cos
from time import sleep
import threading
class DNA(threading.Thread):
def __init__(self, pinData = "P9_11", pinClock = "P9_13", pinCS = "P9_15", increment = 0.3, delay = 10, showdna = True, gap = 1):
threading.Thread.__init__(self)
self.GAP = gap
self.INCREMENT = increment
self.DELAY = delay
self.SHOWDNA = showdna
self.lc = LedControl.LedControl(pinData, pinClock, pinCS, 1)
self.lc.shutdown(0, False)
self.lc.setIntensity(0, 15)
self.lc.clearDisplay(0)
self.x = 0.0
self.c = 0
self.ledBuffer = [0 for i in range(8)]
def run(self):
while True:
#Shuffle down
for i in range(7):
self.ledBuffer[7-i] = self.ledBuffer[6-i]
pos = int((sin(self.x) + 1.0) * 4.0)
self.ledBuffer[0] = 1 << pos
if self.SHOWDNA:
pos2 = int((cos(self.x + 0.6) + 1.0) * 4.0)
self.ledBuffer[0] |= 1 << pos2
if self.c == self.GAP: #Draw the connecting bar
if pos2 < pos:
pos, pos2 = pos2, pos
for i in range(pos, pos2):
self.ledBuffer[0] |= 1 << i
self.c = 0
else:
self.c += 1
for i in range(8):
self.lc.setRow(0, i, self.ledBuffer[i])
self.x += self.INCREMENT
sleep(self.DELAY / 1000.0)
if __name__ == '__main__':
dna = DNA()
dna.start()
while True:
sleep(100)