-
Notifications
You must be signed in to change notification settings - Fork 0
/
spi-test4.py
executable file
·72 lines (59 loc) · 1.57 KB
/
spi-test4.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
64
65
66
67
68
69
70
71
72
#!/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
SLEEPTIME=2
#At the beginning of the program open up the SPI port.
#this is port /dev/spidevX.Y
#Being called as as spi.SPI(X,Y)
#a = spi.SPI(0,0)
#spi.initialize()
status = spi.openSPI(speed=1000000)
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)
while 1:
d.clear()
d.update()
sleep(2)
d.setall(0, 255, 0)
d.update()
sleep(1)
d.setall(255, 0, 0)
d.update()
sleep(1)
d.clear()
d.update()
sleep(1)
for pix in range(pixels-200):
d.set(pix, 255, 255, 255)
d.set(17, 255, 255, 255)
d.update()
d.clear()
sleep(1)
d.update()