Skip to content

Commit

Permalink
First commit to track code progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Bryan committed May 28, 2013
1 parent 1287dcd commit cef3d8c
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 0 deletions.
49 changes: 49 additions & 0 deletions led-display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/python
import spi
from time import sleep

SLEEPTIME=2

status = spi.openSPI(speed=5000000)
print "SPI configuration = ", status
# print "PY: initialising SPI mode, reading data, reading length . . . \n"

# How many total pixels?
pixels = 400

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

# How many pixels in the display do we have?
d = display(400)

while 1:
d.setall(0, 255, 0)
d.update()
sleep(1)
d.setall(255, 0, 0)
d.update()
sleep(1)
d.clear()
d.update()
sleep(1)
80 changes: 80 additions & 0 deletions spi-test3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/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')

61 changes: 61 additions & 0 deletions spi-test4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/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"

pixels = 408


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(408)

while 1:
d.setall(0, 255, 0)
d.update()
sleep(1)
d.setall(255, 0, 0)
d.update()
sleep(1)
d.clear()
d.update()
sleep(1)

0 comments on commit cef3d8c

Please sign in to comment.