Esempio n. 1
0
    def __init__(self, num_leds, num_segments=None, brightness=255):
        # set the total number of LEDs in the strip
        self.num_leds = num_leds
        self.num_segments = num_segments
        self.brightness = brightness
        
        # initialize the list of segment overrides to include all, left and right.
        # This segment list is used to override other segment control based on
        # the bling command itself. For example, we may want to apply a pattern to either
        # the left or right side of the robot.
        led_half = int((self.num_leds/2))
        led_quarter = int((self.num_leds/4))
        self.segments = { 'ALL':          ( 0, self.num_leds ),
                          'LEFT':         ( 0, led_half-1 ),
                          'RIGHT':        ( led_half, int(self.num_leds) ),
                          'RIGHT_FRONT':  ( 0, (led_quarter-1) ),
                          'RIGHT_REAR':   ( led_quarter, (led_quarter+led_quarter-1) ),
                          'LEFT_REAR':    ( (led_quarter*2), ((led_quarter*2)+led_quarter-1) ),
                          'LEFT_FRONT':   ( (led_quarter*3), ((led_quarter*3)+led_quarter-1) )
                        }

        # initialize the driver with the type and count of LEDs that we are using
        # also, define the correct RGB channel order once you have run the test pattern
        # the other parameters are set based on the controlling application. We're using
        # the RaspberryPi as the controller with the SPI port
        self.driver = DriverLPD8806(num=self.num_leds, c_order = ChannelOrder.GRB, SPISpeed=2, use_py_spi=True, dev='/dev/spidev0.0')

        # we are using the LED strip configuration, other available configurations include an LED matrix,
        # but we have only a single strip at this time
        self.led = LEDStrip(self.driver, threadedUpdate=True, masterBrightness=self.brightness)

        # the frames per second is used to control how fast the animation runs. some of the animations
        # work better when run at a low frames per second
        self.fps = None

        # the pattern variable contains the most recent bling pattern that has been assigned
        self.pattern = None
        
        # initialize the bling command parameters to provide reasonable default values for each
        # setting
        self.params = {}
        self.init_params()
        
        self.bling_patterns = bling_patterns.BlingPatterns(self)

        ###### TODO: remove these variables after converting the menu processing to use #####
        ######       the new patterns                                                   #####
        # animation object containing pattern to apply to the LEDs
        self.anim = None

        # flag to indicate whether the selected mode requires animation. Displaying a solid color across all or a range
        # of LEDs does not require animation
        self.animate = True
Esempio n. 2
0
def init_pixels(type, npixels=200):
    try:
        if type == "spi" or type == "raspberry":
            LED_DRIVER = DriverWS2801(npixels)
        else:
            raise ValueError("device type has not in {}".format(
                str(['spi', 'raspberry'])))
    except ImportError as e:
        print("Not able to initialize the driver. Error{}".format(
            str(e.message)))
        print("Use bibliopixel.drivers.dummy_driver")
        LED_DRIVER = DriverDummy(npixels)

    return LEDStrip(LED_DRIVER, masterBrightness=BRIGHTNESS)
def main():
    global led, presets

    parser = argparse.ArgumentParser(description='AllPixel OSC controller',
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--port', dest='port', default=7676,
                        help='Port to listen on')
    parser.add_argument('--num-leds', dest='num_leds', default=194,
                        help='Number of LEDs on strip')
    args = parser.parse_args()

    signal(SIGINT, sig_exit)
    signal(SIGTERM, sig_exit)

    osc = Server(args.port, UDP)
    osc.add_method("/off", None, set_off)
    osc.add_method("/presets", None, set_preset)

    driver = DriverSerial(type=LEDTYPE.WS2801, num=int(args.num_leds), c_order=ChannelOrder.GRB)
    led = LEDStrip(driver)

    presets += [
        LarsonScanners.LarsonScanner(led, color=colors.Cyan, tail=60),
        LarsonScanners.LarsonRainbow(led, tail=60),
        Rainbows.Rainbow(led),
        PartyMode.PartyMode(led, [colors.White, colors.Blue]),
        FireFlies.FireFlies(led, [colors.Gold, colors.Red], width=12, count=4),
        WhiteTwinkle.WhiteTwinkle(led),
        Wave.Wave(led, color=colors.Cyan, cycles=4),
        ColorChase.ColorChase(led, color=colors.Cyan, width=20)
    ]

    set_preset('', [0, 50], '', '')

    while True:
        osc.recv(100)
Esempio n. 4
0
    tp = range(ind(nleft, ntop), ind(nright, ntop), 1)
    sright = range(ind(nright, ntop), ind(nright, nbot), -rounds)
    bt = range(ind(nright, nbot), ind(nleft, nbot), -1)
    path = sleft + tp + sright + bt
    if len(path) == 0:
        path = [ind(nleft, nbot)]
    path = map(lambda x: (shift + x) % nled, path)
    log.logger.info("pathgen({}, {}, {}, {}, {}) is {}".format(
        nleft, nright, nbot, ntop, shift, path))
    return path


if __name__ == '__main__':
    drivermaster = DriverVisualizer(160, pixelSize=62, stayTop=False)
    #ledmaster = LEDStrip(drivermaster, threadedUpdate=True)
    ledmaster = LEDStrip(drivermaster)

    lnin = [255, 222, 200, 150, 125]
    bluedimming = [(0, 0, i) for i in lnin]
    reddimming = [(i, 0, 0) for i in lnin]
    greendimming = [(0, i, 0) for i in lnin]
    cyandimming = [(0, i, i) for i in lnin]
    whitedimming = [(i, i, i) for i in lnin]

    # Worm arguments
    wormblue = (bluedimming, pathgen(5, 10, 0, 9), 1, 1)
    wormred = (reddimming, pathgen(1, 14, 1, 8), 1, 1)
    wormgreen = (greendimming, pathgen(2, 13, 2, 7), 1, 1)
    wormcyan = (cyandimming, pathgen(3, 12, 3, 6), 1, 1)
    wormwhite = (whitedimming, pathgen(4, 11, 4, 5), 1, 1)
Esempio n. 5
0
wavewhite = ((255, 255, 255), 1)

# Wave slave driver arguments
wavebluepixmap = pathgen(1, 15, 0, 9)
waveredpixmap = pathgen(1, 14, 1, 8)
wavegreenpixmap = pathgen(2, 13, 2, 7)
wavecyanpixmap = pathgen(3, 12, 3, 6)
wavewhitepixmap = pathgen(4, 11, 4, 5)

# List of triple (animation arguments, slavedriver argument, fps)
wavedatalist = [(waveblue, wavebluepixmap, 5), (wavered, waveredpixmap, 6),
                (wavegreen, wavegreenpixmap, 7), (wavecyan, wavecyanpixmap, 8),
                (wavewhite, wavewhitepixmap, 9)]

# dummy  LED strips must each have their own slavedrivers
ledslaves = [LEDStrip(DriverSlave(len(sarg), pixmap=sarg, pixheights=-1), threadedUpdate=False) \
             for aarg, sarg, fps in wavedatalist]

# Make the animation list
# Wave animations as list pairs (animation instances, fps) added
animationlist = [(WA.Wave(ledslaves[i], *wd[0]), wd[2])
                 for i, wd in enumerate(wavedatalist)]


# needed to run on pixelweb
def genParams():
    return {"start": 0, "end": -1, "animcopies": animationlist}


if __name__ == '__main__':
    masteranimation = MasterAnimation(ledmaster, animationlist, runtime=2)
Esempio n. 6
0
        self._activecount += amt
        self._activecount %= self._cyclelen
        self._step += amt


#load driver and controller and animation queue
#driver = DriverLPD8806(160,c_order = ChannelOrder.GRB, SPISpeed = 16)
#driver = DriverVisualizer(160, 16, 10, 30, stayTop=True)
# by setting to 160 pixels and size 31 will produce 10 h, 16 wide
#  wrapped
driver = DriverVisualizer(160, pixelSize=31, stayTop=True)

# not much difference whether set threadedUpdate to True or False
#  But CANT stop the updateThread see end of code
#led = LEDStrip(driver, threadedUpdate=True)
led = LEDStrip(driver)

#print led.buffer
#print len(led.buffer)
#print led.bufByteCount

ledfake = LEDStrip(driver)


def dummy():
    print 'hello'


ledfake.update = dummy

# Set up 3 worms - my 160 led strip is wound in a spiral around a cylinder approximately
Esempio n. 7
0
import time
from operator import or_, ior, ixor
import matplotlib.pyplot as plt
import BiblioPixelAnimations.matrix.bloom as BA
import BiblioPixelAnimations.strip.Wave as WA

import sys
sys.path.append('D:\Bill\SpyderWork')  # to get wormanimclass
from wormanimclass import Worm, pathgen

drivermaster = DriverVisualizer(160,
                                pixelSize=62,
                                stayTop=False,
                                maxWindowWidth=1024)
# drivermaster = DriverVisualizer(160, pixelSize=31, stayTop=False, , maxWindowWidth=512)
ledmaster = LEDStrip(drivermaster, threadedUpdate=False)

# segment colors
lnin = [255, 222, 200, 150, 125]
bluedimming = [(0, 0, i) for i in lnin]
reddimming = [(i, 0, 0) for i in lnin]
greendimming = [(0, i, 0) for i in lnin]
cyandimming = [(0, i, i) for i in lnin]
whitedimming = [(i, i, i) for i in lnin]

# Worm arguments = (segment colors, path, cyclelength, direction, height)
wormblue = (bluedimming, None, 1, 1, 6)
wormred = (reddimming, None, 1, 1, 2)
wormgreen = (greendimming, None, 1, 1, 3)
wormcyan = (cyandimming, None, 1, 1, 4)
wormwhite = (whitedimming, None, 1, 1, 5)
from WormThreadTest import pathgen

DEBUG = 0

# Configurable values
# spi = spidev.SpiDev()
# note spi.writebytes, spi.xfer2, spi.xfer must take list NOT bytearray or
#   they will fail and terminate program
# Open SPI device
# spi.open(0,0)

driver = DriverVisualizer(160, pixelSize=62, stayTop=True)
#driver = DriverVisualizer(160, pixelSize=31, stayTop=True)

threadedUpdate = True
led = LEDStrip(driver, threadedUpdate=threadedUpdate)

#def dum():
#    pass
#
#led.update = dum


class Worm:
    # colors a list the worm segment (starting with head) colors of 9 bit integers first hi 3 bits red level, next 3 green, next 3 blue
    #   color levels correspond to 0b0,0b1,0b11,0b111,0b1111,0b11111,0b111111,0b1111111
    # path a list of the LED indices over which the worm will travel (from 0 to 159 for 5 m strip)
    # cyclelen controls speed, worm movement only when LED upload cycles == 0 mod cyclelen
    # height (of worm segments) is same length as colors: higher value worms segments go over top of lower value worms
    #    equal value segments are xor'd with LED strip
    def __init__(self,

class Dummy(BaseStripAnim):
    def __init__(self, led, start=0, end=-1):
        super(Dummy, self).__init__(led, start, end)

    def step(self, amt=1):
        pass


if __name__ == '__main__':
    pixelWidth = 5
    masterBrightness = 155
    driver = DriverVisualizer(160, pixelSize=8, stayTop=True)
    led = LEDStrip(driver,
                   pixelWidth=pixelWidth,
                   masterBrightness=masterBrightness)
    dum = Dummy(led)

    print "masterBrightness is {}".format(dum._led.masterBrightness)
    dum._led.all_off()
    print "Pixel width {}".format(dum._led.pixelWidth)
    print "Numer of scaled pixels {}".format(dum._led.numLEDs)
    print "set scaled pixel 14 to red and scaled pixel 15 to green"
    print "these colors are scaled via masterBrightness"
    dum._led.set(14, (255, 0, 0))
    dum._led.update()
    px1c = (0, 255, 0)
    dum._led.set(15, px1c)
    dum._led.update()
    print "But when ask for pixel 14s color get {}".format(dum._led.get(14))
Esempio n. 10
0
wormbluepixmap = pathgen(3, 12, 0, 9)
wormredpixmap = pathgen(4, 11, 1, 8)
wormgreenpixmap = pathgen(5, 10, 2, 7)
wormcyanpixmap = pathgen(6, 9, 3, 6)
wormwhitepixmap = pathgen(7, 8, 4, 5)

# List of triple (animation arguments, slavedriver argument, fps)
wormdatalist = [(wormblue, wormbluepixmap, 20), (wormred, wormredpixmap, 20),
                (wormgreen, wormgreenpixmap, 19),
                (wormcyan, wormcyanpixmap, 21),
                (wormwhite, wormwhitepixmap, 16)]

# dummy  LED strips must each have their own slavedrivers
ledslaves = [
    LEDStrip(DriverSlave(len(sarg), pixmap=sarg, pixheights=-1),
             threadedUpdate=False,
             masterBrightness=255) for aarg, sarg, fps in wormdatalist
]

# Make the animation list
# Worm animations as list pairs (animation instances, fps) added
animationlist = [(Worm(ledslaves[i], *wd[0]), wd[2])
                 for i, wd in enumerate(wormdatalist)]


# needed to run on pixelweb
def genParams():
    return {"start": 0, "end": -1, "animcopies": animationlist}


if __name__ == '__main__':
Esempio n. 11
0
thanksgiving = [(00,102,51), (00,204,153), (00,204,102)]

class Kitt(BaseStripAnim):
    def __init__(self, led):
        super(Kitt, self).__init__(led)
        self.length = 32*5

    def step(self, amt=1):
        middle = self.length / 2
        self._led.set(middle, orange)
        self._step += amt

speed = 0.001
speed = 16.0
led = LEDStrip(DriverLPD8806(32*5, dev="/dev/spidev0.0", SPISpeed=speed))
#anim = StripTest(led)
#anim = Halloween1(led)

from strip_animations import *
anim = RainbowCycle(led)
#anim = ColorPattern(led, [purple, orange], 10)
#anim = ColorPattern(led, thanksgiving, 32)
anim = ColorFade(led, [blue], 2) # maybe?
#anim = ColorFade(led, thanksgiving, 3)
#anim = ColorChase(led, orange, 10)
anim = FireFlies(led, [blue, red], width=3, count=2)
#anim = LarsonScanner(led, blue, 10) # cat toy
#anim = LarsonScanner(led, orange, 10) # cat toy
#anim = Kitt(led)
#anim = LarsonRainbow(led)
Esempio n. 12
0
wormredpixmap = pathgen(1, 14, 1, 8)
wormgreenpixmap = pathgen(2, 13, 2, 7)
wormcyanpixmap = pathgen(3, 12, 3, 6)
wormwhitepixmap = pathgen(4, 11, 4, 5)

# List of triple (animation arguments, slavedriver argument, fps)
wormdatalist = [(wormblue, wormbluepixmap, 24), (wormred, wormredpixmap, 20),
                (wormgreen, wormgreenpixmap, 16),
                (wormcyan, wormcyanpixmap, 12),
                (wormwhite, wormwhitepixmap, 8)]

# dummy strips must each have their own slavedriver as thread is attached
# to the driver
# Here using worm path for pixmap
ledslaves = [
    LEDStrip(DriverSlave(len(sarg), pixmap=sarg, pixheights=-1),
             threadedUpdate=True) for aarg, sarg, fps in wormdatalist
]

# dummy  LED strips must each have their own slavedrivers
ledslaves = [LEDStrip(DriverSlave(len(sarg), pixmap=sarg, pixheights=-1), threadedUpdate=False) \
             for aarg, sarg, fps in wormdatalist]

# Make the animation list
# Worm animations as list pairs (animation instances, fps) added
animationlist = [(Worm(ledslaves[i], *wd[0]), wd[2])
                 for i, wd in enumerate(wormdatalist)]

ledslaveb = LEDMatrix(DriverSlave(160, None, 0),
                      width=16,
                      height=10,
                      threadedUpdate=False)
Esempio n. 13
0
    bt = range(ind(nright, nbot), ind(nleft, nbot), -1)
    path = sleft + tp + sright + bt
    if len(path) == 0:
        path = [ind(nleft, nbot)]
    path = map(lambda x: (shift + x) % nled, path)
    log.logger.info("pathgen({}, {}, {}, {}, {}) is {}".format(
        nleft, nright, nbot, ntop, shift, path))
    return path


if __name__ == '__main__':
    drivermaster = DriverVisualizer(160, pixelSize=62, stayTop=False)
    # dummy strips must each have their own slavedriver as thread is attached
    # to the driver
    ledslaves = [
        LEDStrip(DriverSlave(160, 0), threadedUpdate=True) for _ in range(5)
    ]
    ledmaster = LEDStrip(drivermaster, threadedUpdate=True)

    lnin = [255, 222, 200, 150, 125]
    bluedimming = [(0, 0, i) for i in lnin]
    reddimming = [(i, 0, 0) for i in lnin]
    greendimming = [(0, i, 0) for i in lnin]
    cyandimming = [(0, i, i) for i in lnin]
    whitedimming = [(i, i, i) for i in lnin]

    wormblue = Worm(ledslaves[0], bluedimming, pathgen(5, 10, 0, 9), 1, 1)
    wormred = Worm(ledslaves[1], reddimming, pathgen(1, 14, 1, 8), 1, 1)
    wormgreen = Worm(ledslaves[2], greendimming, pathgen(2, 13, 2, 7), 1, 1)
    wormcyan = Worm(ledslaves[3], cyandimming, pathgen(3, 12, 3, 6), 1, 1)
    wormwhite = Worm(ledslaves[4], whitedimming, pathgen(4, 11, 4, 5), 1, 1)
Esempio n. 14
0
    sleft = range(ind(nleft, nbot), ind(nleft, ntop), rounds)
    tp = range(ind(nleft, ntop), ind(nright, ntop), 1)
    sright = range(ind(nright, ntop), ind(nright, nbot), -rounds)
    bt = range(ind(nright, nbot), ind(nleft, nbot), -1)
    path = sleft+tp+sright+bt
    if len(path) == 0:
        path = [ind(nleft, nbot)]
    path = map(lambda x: (shift+x) % nled, path)
    log.logger.info("pathgen({}, {}, {}, {}, {}) is {}".format(nleft, nright, nbot, ntop, shift, path))
    return path 

drivermaster = DriverVisualizer(160, pixelSize=62, stayTop=False, maxWindowWidth=1024)
# using pixelSize 62 and changed code of visualizer.py to have maxWindowWidth=1024
#drivermaster = DriverVisualizer(160, pixelSize=31, stayTop=False)
#ledmaster = LEDStrip(drivermaster, threadedUpdate=True)
ledmaster = LEDStrip(drivermaster)

lnin = [255, 222, 200, 150, 125]
bluedimming = [(0, 0, i) for i in lnin]
bluedimming = [(0, 0, 0) for i in lnin]
reddimming = [(i, 0, 0) for i in lnin]
greendimming = [(0, i, 0) for i in lnin]
cyandimming = [(0, i, i) for i in lnin]
whitedimming = [(i, i, i) for i in lnin]

# Worm arguments
wormblue = (bluedimming, pathgen(5, 10, 0, 9), 1, 1, 6)
wormred = (reddimming, pathgen(1, 14, 1, 8), 1, 1, 2)
wormgreen = (greendimming, pathgen(2, 13, 2, 7), 1, 1, 3)
wormcyan = (cyandimming, pathgen(3, 12, 3, 6), 1, 1, 4)
wormwhite = (whitedimming, pathgen(4, 11, 4, 5), 1, 1, 5)
Esempio n. 15
0
        path = [ind(nleft, nbot)]
    path = map(lambda x: (shift + x) % nled, path)
    log.logger.info("pathgen({}, {}, {}, {}, {}) is {}".format(
        nleft, nright, nbot, ntop, shift, path))
    return path


if True:  #__name__ == '__main__':
    drivermaster = DriverVisualizer(160,
                                    pixelSize=62,
                                    stayTop=False,
                                    maxWindowWidth=1024)
    # using pixelSize 62 and changed code of visualizer.py to have maxWindowWidth=1024
    #drivermaster = DriverVisualizer(160, pixelSize=31, stayTop=False)
    #ledmaster = LEDStrip(drivermaster, threadedUpdate=True)
    ledmaster = LEDStrip(drivermaster)

    lnin = [255, 222, 200, 150, 125]
    bluedimming = [(0, 0, i) for i in lnin]
    bluedimming = [(0, 0, 0) for i in lnin]
    reddimming = [(i, 0, 0) for i in lnin]
    greendimming = [(0, i, 0) for i in lnin]
    cyandimming = [(0, i, i) for i in lnin]
    whitedimming = [(i, i, i) for i in lnin]

    # Worm arguments
    wormblue = (bluedimming, pathgen(5, 10, 0, 9), 1, 1, 6)
    wormred = (reddimming, pathgen(1, 14, 1, 8), 1, 1, 2)
    wormgreen = (greendimming, pathgen(2, 13, 2, 7), 1, 1, 3)
    wormcyan = (cyandimming, pathgen(3, 12, 3, 6), 1, 1, 4)
    wormwhite = (whitedimming, pathgen(4, 11, 4, 5), 1, 1, 5)
Esempio n. 16
0
        self._brightness +=  self._dir * amt
        if self._brightness < 0:
            self._brightness = 0
            self._dir = 1
        elif self._brightness > 255:
             self._brightness = 255
             self._dir = -1            
             
        self._led.changeBrightness(self._brightness)
        #print "buffer {} unscaled {}".format(self._led.buffer[0:3],  self._led.unscaledbuffer[0:3])
        self._step += amt
        self._count += 1

if __name__ == '__main__':
    driver = DriverVisualizer(160, pixelSize=62, stayTop=False, maxWindowWidth=1024)
    led = LEDStrip(driver, masterBrightness=255, masterBrightnessLimit=200)

    w1 = Worm(led, [(255, 100, 50)]*10)
    w2 = Worm(led, [(2, 100, 250)]*10)
    dim = dimLights(led)

#    animQ.addAnim(w2, fps=10, max_steps=40)
    #animQ.addAnim(dim, amt=5, fps=30, max_steps=70)
#    animQ.addAnim(w1, fps=5, max_steps = 10)
 
 
    animQ = AnimationQueue(led)
    animQ.addAnim(dim, amt=10, fps=5, max_steps=40, threaded=True)
    animQ.addAnim(w1, fps=5, max_steps=20)
    animQ.addAnim(w2, fps=5, max_steps=20)
                     
Esempio n. 17
0
from bibliopixel.animation import BaseStripAnim
from bibliopixel import LEDStrip
from bibliopixel.drivers.visualizer import DriverVisualizer
from bibliopixel import colors

from penner import OutBounce
import strip_animations as sa

speed = 16.0
led = LEDStrip(DriverVisualizer(32))
anim = sa.BubbleSort(led)

anim.run()
Esempio n. 18
0
# ### Shell commands to reset spidev

# In[ ]:

from subprocess import call
call(["sudo", "chmod", "a+rw", "/dev/spidev0.0"])


# ### Initial setup

# In[ ]:

numLeds= 10 * 10
driver=DriverLPD8806(numLeds, ChannelOrder.BRG)
led=LEDStrip(driver)

r = (0, 50, 0) # LEDs are GRB; 255 is too bright
g = (50, 0, 0)
b = (0, 0, 50)


# ### Each LED turns on serially
# ####Once done they all flash ON & OFF till user ends the program with CTRL + C

# In[ ]:

led.fillRGB(0,0,0) # turns everything off
led.update()

for i in range (numLeds):
Esempio n. 19
0
#!/usr/bin/env python

from daylight import SunRange
from bibliopixel.drivers.visualizer import *
from bibliopixel import LEDStrip
import time

num_leds = 10

driver = DriverVisualizer(num_leds, stayTop=True)
led_strip = LEDStrip(driver)
pdx = SunRange()

def nightRemainingRGB():
    return (178, 102, 255)

def nightFadedRGB():
    return (76, 0, 153)

def dayRemainingRGB():
    return (255, 255, 51)

def dayFadedRGB():
    return (150, 150, 0)


led_strip.fill(dayRemainingRGB())
led_strip.update()

for i in range(0, num_leds):
    time.sleep(1)