Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 516
» Latest member: lebaobei123
» Forum threads: 88
» Forum posts: 404

Full Statistics

Online Users
There are currently 7 online users.
» 0 Member(s) | 7 Guest(s)

Latest Threads
New tdsp color list Pytho...
Forum: BiblioPixel Development
Last Post: roykerman222
03-14-2017, 05:13 AM
» Replies: 1
» Views: 1,506
Art-Net Support
Forum: AllPixel Support
Last Post: dfive
03-04-2017, 03:09 PM
» Replies: 3
» Views: 965
Animated Porch Lights
Forum: Show-And-Tell
Last Post: emilyford33
02-22-2017, 07:18 AM
» Replies: 3
» Views: 4,505
Project Northern Lights
Forum: Show-And-Tell
Last Post: mlapasa
01-25-2017, 12:05 PM
» Replies: 3
» Views: 720
What sources do people us...
Forum: General Discussion
Last Post: stharocks77
01-14-2017, 11:39 AM
» Replies: 3
» Views: 7,964
AllPixels to drive a 6x9x...
Forum: AllPixel Support
Last Post: ghowles
01-12-2017, 12:30 AM
» Replies: 5
» Views: 1,080
Need help to determine a ...
Forum: BiblioPixel Support
Last Post: vied12
12-31-2016, 01:41 PM
» Replies: 3
» Views: 801
LarsonScanner Problem
Forum: BiblioPixel Support
Last Post: kwalkerk
12-25-2016, 01:00 PM
» Replies: 4
» Views: 693
Individual LED control or...
Forum: General Discussion
Last Post: Adam
12-24-2016, 05:41 PM
» Replies: 5
» Views: 1,198
Matrix dots made of multi...
Forum: General Discussion
Last Post: jack
12-24-2016, 07:47 AM
» Replies: 8
» Views: 3,597

 
  Led Strip - Random Colour
Posted by: Sparkacus - 01-23-2015, 02:42 AM - Forum: User Animations - Replies (3)

I'm a complete newb when it comes to electronics and python, but I thought I would share what I think is simple code that may help a beginner.

I'm running a WS2801 32 led strip via SPI on a Raspberry Pi.

I couldn't actually find any simple first time example to show off a simple animation...but then I didn't look too hard Dodgy Wink It was nearing midnight after a hard days work. Maybe there is something on Github.

This animation works for me. It's supposed to randomly select an led and fill with a random colour. Once the whole strip is coloured, it then works in reverse by switching a random led off. This whole process will continue to loop.

Like I said I'm a newb so if you hardcore Python programers are laughing, which I don't blame you, please provide some tips Smile. I didn't bother to create a class or define functions as in my opinion these layouts are easier to understand for a beginner, although you're more than welcome to correct me.


Code:
from bibliopixel.drivers.WS2801 import DriverWS2801
from bibliopixel.led import *
import random


led_number = 32
led = LEDStrip(DriverWS2801(num=led_number))

c = [colors.Red, colors.Green, colors.Blue]

while True:
    led_index = []

    # Append 0 - led_number to led_index list, i.e [0, 1, 2, 3, 4, .., 31]
    for index1 in range(led_number):
        led_index.append(index1)

    # Randomly select an led and color. The selected led is then removed from the list so it's not selected again.
    for each_led1 in range(led_number):
        x1 = random.choice(led_index)
        y1 = random.choice(c)
        led.set(x1, y1)
        led.update()
        led_index.remove(x1)

        # Adjust the sleep time to speed up/down the effect
        time.sleep(0.05)

    # Append 0 - led_number to led_index list again
    for index2 in range(led_number):
        led_index.append(index2)

    # Randomly select an led and switch it off. The led_index is then removed.
    for each_led2 in range(led_number):
        x2 = random.choice(led_index)
        y2 = colors.Off
        led.set(x2, y2)
        led.update()
        led_index.remove(x2)

        # Adjust the sleep time to speed up/down the effect
        time.sleep(0.05)

Print this item

  Circlepop
Posted by: kasperfish - 01-12-2015, 03:48 PM - Forum: User Animations - Replies (3)





code

Code:
#reusable helper class
class Circle():
   def __init__(self, posy, posx, color, frameratio, radius):
       self._y=posy
       self._x=posx
       self._color= color
       self.frameratio=frameratio # animation speed of a single circle relative to the fps of the actual animation.
       self._radius=radius
   def grow(self, amt = 1):
       self._radius += amt

   def changeColor(self, amt = 8):
       self._color += amt
       if self._color >=360:
           self._color%=360

#animation class
class CirclePop(BaseMatrixAnim):
   def __init__(self, led, bgcolor=colors.Off):
       super(CirclePop, self).__init__(led)
       self.cont = [] # list for storing Circle objects
       self.max_circ = 3 # max number of cirles in the list
       self.prob_circ = 8 # probability for adding a new Circle to the list. higher values make it less probable.
       self.bgcolor = bgcolor
       self.addCircle() # add a first circle to our list
       
   def step(self, amt=1):
       self._led.fillScreen(self.bgcolor) #background color
       # check if we may add a new circle to the list
       if not random.randrange(self.prob_circ) and len(self.cont) <= self.max_circ:
           self.addCircle()

       # loop through our circles, draw and update them
       for circ in self.cont:
           self._led.drawCircle(circ._x, circ._y, circ._radius, colors.hue2rgb_360(circ._color))

           if not self._step%circ.frameratio:
               circ.grow()
               circ.changeColor()

       self._step+=amt
       # don't let our step counter grow endlessly
       if self._step>=100:
           self._step%=100

       # remove circles that have grown bigger than our matrix
       self.cont = [c for c in self.cont if c._radius != max(self._led.height, self._led.width)+1]

   def addCircle(self):
       # let's add some randomness. You can play with these values.
       posx = random.randint(3, self._led.width-3)
       posy = random.randint(3, self._led.height-3)
       color = random.randint(1, 359)
       frameratio = random.choice([1,2]) # choose between 2 speeds fps/1 and fps/2.
       radius = 1
       self.cont.append(Circle(posy, posx, color, frameratio, radius))

usage
Code:
anim = CirclePop(led)
anim.run(max_steps = 2000, fps = 20, max_cycles=1)



Attached Files
.txt   circlepop.txt (Size: 2.29 KB / Downloads: 5)
Print this item

  Animated Porch Lights
Posted by: Adam - 01-03-2015, 07:43 PM - Forum: Show-And-Tell - Replies (3)





This project was originally installed last year just before Halloween, but with my old RPi-LPD8806 library which was, well, very slow. With 360 LEDs total, the old library could barely manage 10fps. Over a year later and a lot of work later, BiblioPixel is much more capable and I can push over 100fps.

The build consists of 10 meters of 36 pixel/m LPD8806 LEDs, wrapped in a waterproof sleeve. A Raspberry Pi controls the strip directly via the SPI output (it was built before the AllPixel). The Pi and a 20A power supply are mounted in a NEMA 4 enclosure for maximum weather protection.

The old version had a web interface for controlling it, but the BiblioPixel interface is completely different from RPi-LPD8806 so that had to be ditched for now... probably again in the future. For now, I put together a colorful display that was used for New Years Eve:

Code:
from bibliopixel.drivers.LPD8806 import *
from bibliopixel import *
from bibliopixel.animation import *
from strip_animations import *
import bibliopixel.colors as colors


FPS = 20
rainbow = [colors.Red, colors.Orange, colors.Yellow, colors.Green, colors.Blue, colors.Indigo, colors.Violet]

driver = DriverLPD8806(360, c_order=ChannelOrder.BRG, use_py_spi=True, dev="/dev/spidev0.0", SPISpeed=2)

led = LEDStrip(driver)

try:
    while True:
        led.all_off()

        anim = ColorFade(led, rainbow, step=10)
        anim.run(fps = FPS, max_steps=45*len(rainbow))

        anim = FireFlies(led, rainbow, width=10, count=4)
        anim.run(fps = 10, max_steps=100)

        anim = LarsonRainbow(led, tail=36)
        anim.run(amt = 3, fps = FPS, max_steps=(360*2)/3)

        anim = RainbowCycle(led)
        anim.run(amt = 2, fps = FPS, max_steps=256)

except KeyboardInterrupt:
    led.all_off()
    led.update()

Print this item

Wink Check The Wiki!
Posted by: Dan - 01-01-2015, 02:27 PM - Forum: BiblioPixel Support - No Replies

https://github.com/ManiacalLabs/BiblioPixel/wiki

The BiblioPixel Wiki will be an on-going source of documentation for the BiblioPixel library. Be sure to take a look if you're having trouble or just want to learn more about how the library works.

Print this item

  Binary Epoch Strip Animation
Posted by: Dan - 01-01-2015, 02:22 PM - Forum: User Animations - Replies (1)





From the YouTube video description:
"Using 15m of LPD8806 lights and the AllPixel to turn my tree into a giant Binary Epoch clock. Based on the idea behind our Binary Epoch Clock Kit, the Unix epoch time (number of seconds since 12:00am Jan 1 1970) is represented in binary notation. The strand of lights shows 32 places. Green represents a 'one', red, a 'zero'. The top of the tree is the Least Significant Bit, the bottom the Most Significant Bit. Practical clock? No. Festive? Very."

The 'BEClock' class (shown below) can be added to the BiblioPixel 'strip_animations.py' file.

Code:
class BEClock(BaseStripAnim):
   """Binary Epoch Clock"""

   def __init__(self, led, onColor, offColor, bitWidth, bitSpace, reverse):
        super(BEClock, self).__init__(led, 0, 0)
        self._onColor = onColor
        self._offColor = offColor
        self._bitWidth = bitWidth
        self._bitSpace = bitSpace
        self._reverse = reverse
       
   def step(self, amt = 1):
       z = calendar.timegm(time.gmtime(time.time()))

if self._reverse:
for i in range(32):
if (z & (1 << i)) > 0:
self._led.fill(self._onColor,(self._bitSpace+self._bitWidth)*(31-i),((self._bitSpace+self._bitWidth)*(31-i))+self._bitWidth)
else:
self._led.fill(self._offColor,(self._bitSpace+self._bitWidth)*(31-i),((self._bitSpace+self._bitWidth)*(31-i))+self._bitWidth)
else:
for i in range(32):
if (z & (1 << i)) > 0:
self._led.fill(self._onColor,(self._bitSpace+self._bitWidth)*i,((self._bitSpace+self._bitWidth)*i)+self._bitWidth)
else:
self._led.fill(self._offColor,(self._bitSpace+self._bitWidth)*i,((self._bitSpace+self._bitWidth)*i)+self._bitWidth)
       
self._step = 0

Usage:

Code:
from strip_animations import BEClock
anim = BEClock(led, onColor = colors.Green, offColor = colors.Red, bitWidth = 5, bitSpace = 12, reverse = True)


'led' is your 'LEDStrip' LED Display class (with appropriate LED driver supplied).
'onColor' is the color that will represent a binary '1'
'offColor' is the color that will represent a binary '0'
'bitWidth' is how many pixels wide each bit representation will be
'bitSpace' is the number of blank pixels between each bit representation
'reverse' allows the animation to be flipped on the strip (0 bit at the start or end of the strip).

Print this item

  WyoLum TinyTiM Rework Boards
Posted by: Dan - 01-01-2015, 02:12 PM - Forum: Show-And-Tell - Replies (1)

Our friends over at WyoLum.com sent us a pair of TinyTiM LED display modules that were of the "ding and dent" variety for use in AllPixel testing and general playing around with blinky things. These displays are awesome. They are 8x8 grids of WS2812 (NeoPixel) LEDs that can be accessed serially or in parallel. For testing with the AllPixel, the solder jumpers for serial communication were bridged. There are input and output connectors on each board so multiple can be chained together.





As far as the rework went, it turns out one just had a bad solder joint on the input connector ground pin. That was a quick fix. The other had two bad LEDs. Fortunately, I had recently acquired a ChipQuik de-soldering kit, which made removal of the problem LEDs a snap. Once the old ones were removed and the PCB cleaned a bit, the new ones were installed and everyone was happy. I also tested the input and output connections on both boards.

The TinyTiMs are due to be released sometime early this year, so keep an eye on shop.wyolum.com for more info. And be sure to stop by our site to check out the AllPixel.

[Image: TinyTims_SerialInGroundSolderJoint.jpg]

[Image: TinyTims_Inspection-e1420135547757.jpg]

[Image: TinyTims_ReadyToRepair.jpg]

Print this item

  Submission Guidelines
Posted by: Adam - 12-30-2014, 08:57 PM - Forum: User Animations - No Replies

For works in progress, feel free to post your animation code here. If it is fairly short, post inside code tags. Otherwise, please just attach as a file. If you feel confident in your code, consider submitting it to our animation GitHub repository. Fork the repository to your own GitHub repository, add your animation in a separate, commented file, to either the matrix or strip folder and submit a pull request.

Print this item