-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspi-test3.py
executable file
·80 lines (67 loc) · 3.34 KB
/
spi-test3.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
73
74
75
76
77
78
79
#!/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=5000000)
print "SPI configuration = ", status
# print "PY: initialising SPI mode, reading data, reading length . . . \n"
# Blue
#data = ["00000000000010000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF10000FF"]
# Green
# data = ["000000000000100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00100FF00"]
def LEDspit(COLOR):
#data = ["0000000000001" + COLOR * (8 * 50 + 8) ]
# data = (0, ) * 50 + 0099991
# Start bits for LEDs
basedata = 0, 0, 0, 1,
# 62 * 4 bytes + 4 bytes works- 63 craps out, as PyArg_ParseTupleAndKeywords function only seems to support ints of 32 bits.
data = basedata + (50, 0, 255, 1) * 408
# data = tuple(data)
#Calculates the length, and devides by 2 for two bytes of data sent.
# length_data = len(data[0])/2
#transfers data string
#print 'Value transfered to C spimodule:',data
#for i, printdata in enumerate(data):
spi.transfer((data))
#sleep(SLEEPTIME)
data = basedata + (0, 255, 0, 1) * 408
spi.transfer((data))
# sleep(SLEEPTIME)
# data = tuple(data)
#data = (50, 0, 255, 1) * 62
#spi.transfer((data))
#data = (50, 0, 255, 1) * 62
#spi.transfer((data))
#data = (50, 0, 255, 1) * 62
#spi.transfer((data))
#data = (50, 0, 255, 1) * 62
#spi.transfer((data))
#At the end of your program close the SPI port
#a.close()
while True:
LEDspit('FF00001')
LEDspit('00FF001')
LEDspit('0000FF1')
LEDspit('1111FF1')
LEDspit('2222FF1')
LEDspit('3333FF1')
LEDspit('4444FF1')
LEDspit('5555FF1')
LEDspit('6666FF1')
LEDspit('7777FF1')
LEDspit('8888FF1')
LEDspit('9999FF1')
LEDspit('A9A9FF1')
LEDspit('B9B9FF1')
LEDspit('C9C9FF1')
LEDspit('D9D9FF1')
LEDspit('E9E9FF1')
LEDspit('F9F9FF1')