-
Notifications
You must be signed in to change notification settings - Fork 0
/
spi-test-2b2.spi
executable file
·58 lines (48 loc) · 1.36 KB
/
spi-test-2b2.spi
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
#!/usr/bin/python
# Python example for SPI bus, written by Brian Hensley
#This script will take any amount of Hex values and determine
#the length and then transfer the data as a string to the "spi" module
import spi
from time import sleep
#At the beginning of the program open up the SPI port.
status = spi.openSPI(speed=5000000)
print "SPI configuration = ", status
# print "PY: initialising SPI mode, reading data, reading length . . . \n"
pixels = 416
class display(object):
def __init__(self, pixels):
self.pixels = pixels
self.clear()
def update(self):
spi.transferrgb(self.red, self.green, self.blue)
def set(self, pos, rv, gv, bv):
'''set pixel at pos to rgb'''
self.red[pos] = rv
self.green[pos] = gv
self.blue[pos] = bv
def setall(self, rv, gv, bv):
'''set all pixels to rgb'''
for pos in xrange(self.pixels):
self.red[pos] = rv
self.green[pos] = gv
self.blue[pos] = bv
def clear(self):
'''clear all pixels to black'''
self.red = [0] * pixels
self.green = [0] * pixels
self.blue = [0] * pixels
d = display(416)
for i in range(3):
d.setall(255, 0, 0)
d.update()
sleep(.25)
d.clear()
d.update()
sleep(.25)
FADETIME=.04
while 1:
for i in range(pixels+1):
print("Setting", i, " to red")
d.set(5, 255, 0, 0)
d.update
sleep(1)