Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'd like to see how this works on larger LED strips #17

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Binary file added 8k8bitpcm.wav
Binary file not shown.
8 changes: 3 additions & 5 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
and checks needed by any script
"""

from time import sleep
from raspledstrip.ledstrip import *
from raspledstrip.animation import *

from raspledstrip.LPD8806 import LPD8806Native
import os.path
import sys

Expand Down Expand Up @@ -42,8 +40,8 @@
""")
sys.exit(2)

num = 36 * 10;
led = LEDStrip(num)
led_count = 36
led = LEDStrip(LPD8806Native(led_count, dev))
#led.setChannelOrder(ChannelOrder.BRG) #Only use this if your strip does not use the GRB order
#led.setMasterBrightness(0.5) #use this to set the overall max brightness of the strip
led.all_off()
111 changes: 56 additions & 55 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,104 +1,105 @@
#!/usr/bin/python
# !/usr/bin/python

from bootstrap import *
from raspledstrip.animation import *

#setup colors to loop through for fade
colors = [
(255.0,0.0,0.0),
(0.0,255.0,0.0),
(0.0,0.0,255.0),
(255.0,255.0,255.0),
(255.0, 0.0, 0.0),
(0.0, 255.0, 0.0),
(0.0, 0.0, 255.0),
(255.0, 255.0, 255.0),
]

step = 0.01
for c in range(4):
r, g, b = colors[c]
level = 0.01
dir = step
while level >= 0.0:
led.fill(Color(r, g, b, level))
led.update()
if(level >= 0.99):
dir = -step
level += dir
#sleep(0.005)
r, g, b = colors[c]
level = 0.01
dir = step
while level >= 0.0:
led.fill(Color(r, g, b, level))
led.update()
if (level >= 0.99):
dir = -step
level += dir
#sleep(0.005)

led.all_off()

#animations - each animation method moves the animation forward one step on each call
#after each step, call update() to push it to the LED strip
#sin wave animations
anim = Wave(led, Color(255, 0, 0), 4)
for i in range(led.lastIndex):
anim.step()
led.update()
#sleep(0.15)
for i in range(led.last_index):
anim.step()
led.update()
#sleep(0.15)

anim = Wave(led, Color(0, 0, 100), 2)
for i in range(led.lastIndex):
anim.step()
led.update()
#sleep(0.15)
for i in range(led.last_index):
anim.step()
led.update()
#sleep(0.15)


#rolling rainbow
anim = Rainbow(led)
for i in range(384):
anim.step()
led.update()
anim.step()
led.update()

led.fillOff()
led.fill_off()

#evenly distributed rainbow
anim = RainbowCycle(led)
for i in range(384*2):
anim.step()
led.update()
for i in range(384 * 2):
anim.step()
led.update()

led.fillOff()
led.fill_off()

#setup colors for wipe and chase
colors = [
Color(255, 0, 0),
Color(0, 255, 0),
Color(0, 0, 255),
Color(255, 255, 255),
Color(255, 0, 0),
Color(0, 255, 0),
Color(0, 0, 255),
Color(255, 255, 255),
]

for c in range(4):
anim = ColorWipe(led, colors[c])
anim = ColorWipe(led, colors[c])

for i in range(num):
anim.step()
led.update()
#sleep(0.03)
for i in range(led_count):
anim.step()
led.update()
#sleep(0.03)

led.fillOff()
led.fill_off()

for c in range(4):
anim = ColorChase(led, colors[c])
anim = ColorChase(led, colors[c])

for i in range(num):
anim.step()
led.update()
#sleep(0.03)
for i in range(led_count):
anim.step()
led.update()
#sleep(0.03)

led.fillOff()
led.fill_off()

#scanner: single color and changing color
anim = LarsonScanner(led, Color(255, 0, 0))
for i in range(led.lastIndex*4):
anim.step()
led.update()
#sleep(0.03)
for i in range(led.last_index * 4):
anim.step()
led.update()
#sleep(0.03)

led.fillOff()
led.fill_off()

anim = LarsonRainbow(led, 2, 0.5)
for i in range(led.lastIndex*4):
anim.step()
led.update()
#sleep(0.03)
for i in range(led.last_index * 4):
anim.step()
led.update()
#sleep(0.03)

led.all_off()

Expand Down
82 changes: 49 additions & 33 deletions raspledstrip/LPD8806.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,55 @@
class LPD8806(object):
try:
import spidev
except ImportError:
pass


class LEDDriver(object):
def __init__(self, led_count):
self.led_count = led_count

def get_led_count(self):
"""
Return the number of LEDs in this device
:rtype: :class:`int`
"""
return self.led_count


class LPD8806Native(LEDDriver):
"""Main driver for LPD8806 based LED strips"""

def __init__(self, leds, use_py_spi = False, dev="/dev/spidev0.0"):
self.leds = leds
def __init__(self, led_count, dev="/dev/spidev0.0"):
super(LPD8806Native, self).__init__(led_count)
self.dev = dev
self.use_py_spi = use_py_spi

if self.use_py_spi:
import spidev
self.spi = spidev.SpiDev()
self.spi.open(0,0)
self.spi.max_speed_hz = 12000000
print 'py-spidev MHz: %d' % (self.spi.max_speed_hz / 1000000.0 )
else:
self.spi = open(self.dev, "wb")
self.spi = open(self.dev, "wb")

#Push new data to strand
def update(self, buffer):
if self.use_py_spi:
for x in range(self.leds):
self.spi.xfer2([i for i in buffer[x]])

self.spi.xfer2([0x00,0x00,0x00]) #zero fill the last to prevent stray colors at the end
self.spi.xfer2([0x00]) #once more with feeling - this helps :)
else:
for x in range(self.leds):
self.spi.write(buffer[x])
self.spi.flush()
#seems that the more lights we have the more you have to push zeros
#not 100% sure why this is yet, but it seems to work
self.spi.write(bytearray(b'\x00\x00\x00')) #zero fill the last to prevent stray colors at the end
self.spi.flush()
self.spi.write(bytearray(b'\x00\x00\x00'))
self.spi.flush()
self.spi.write(bytearray(b'\x00\x00\x00'))
self.spi.flush()
self.spi.write(bytearray(b'\x00\x00\x00'))
def update(self, pixel_buffer):
for x in xrange(self.led_count):
self.spi.write(pixel_buffer[x])
self.spi.flush()
#seems that the more lights we have the more you have to push zeros
#not 100% sure why this is yet, but it seems to work
self.spi.write(bytearray(b'\x00\x00\x00')) #zero fill the last to prevent stray colors at the end
self.spi.flush()
self.spi.write(bytearray(b'\x00\x00\x00'))
self.spi.flush()
self.spi.write(bytearray(b'\x00\x00\x00'))
self.spi.flush()
self.spi.write(bytearray(b'\x00\x00\x00'))
self.spi.flush()


class LPD8806SPI(LEDDriver):
def __init__(self, led_count):
super(LPD8806SPI, self).__init__(led_count)
if not spidev:
raise Exception("SPI module not available")
self.spi = spidev.SpiDev()
self.spi.open(0, 0)
self.spi.max_speed_hz = 18000000
print 'py-spidev MHz: %d' % (self.spi.max_speed_hz / 1000000.0)

def update(self, pixel_buffer):
self.spi.xfer2([item for sublist in pixel_buffer for item in sublist]+[0x00, 0x00, 0x00])
Loading