Created
July 28, 2016 21:37
-
-
Save adammhaile/323124675ab564383d82237d31c7d2de to your computer and use it in GitHub Desktop.
BP Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bibliopixel.drivers.serial_driver import DriverSerial, LEDTYPE, ChannelOrder | |
from bibliopixel import LEDStrip | |
import bibliopixel.colors as colors | |
from time import sleep | |
driver = DriverSerial(LEDTYPE.NEOPIXEL, 10, c_order=ChannelOrder.GRB) | |
led = LEDStrip(driver, threadedUpdate=False, masterBrightness=255, pixelWidth=1) | |
try: | |
while True: | |
led.fill(colors.Red) | |
led.update() | |
sleep(1) | |
led.fill(colors.Green) | |
led.update() | |
sleep(1) | |
led.fill(colors.Blue) | |
led.update() | |
sleep(1) | |
led.fill(colors.Off) | |
led.update() | |
sleep(1) | |
except: | |
led.all_off() | |
led.update() | |
sleep(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from bibliopixel.drivers.driver_base import DriverBase, ChannelOrder | |
from bibliopixel import gamma | |
from neopixel import * | |
# Default LED strip configuration: | |
# num = 16 # Number of LED pixels. | |
# ledPin = 18 # GPIO pin connected to the pixels (must support PWM! pin 13 or 18 on RPi 3). | |
# ledFreqHz = 800000 # LED signal frequency in hertz (800khz or 400khz) | |
# ledDma = 5 # DMA channel to use for generating signal (Between 1 and 14) | |
# ledInvert = 0 # 1 to invert the signal (when using NPN transistor level shift) | |
# ledType = 0x081000 (RGB = 0x100800, RBG = 0x100008, GRB = 0x081000, GBR = 0x080010, BRG = 0x001008, BGR = 0x000810) | |
class WS281XDriver(DriverBase): | |
def __init__(self, num=16, gamma=gamma.NEOPIXEL, c_order=ChannelOrder.RGB, ledPin=18, ledFreqHz=800000, ledDma=5, ledInvert=0): | |
super(WS281XDriver, self).__init__(num, c_order=c_order, gamma=gamma) | |
self.gamma = gamma | |
self._strip = Adafruit_NeoPixel( | |
num, ledPin, ledFreqHz, ledDma, ledInvert, 255, 0, 0x081000) | |
# Intialize the library (must be called once before other functions). | |
self._strip.begin() | |
# WS2812 requires gamma correction so we run it through gamma as the | |
# channels are ordered | |
def _fixData(self, data): | |
for a, b in enumerate(self.c_order): | |
self._buf[a:self.numLEDs * 3:3] = [self.gamma[v] | |
for v in data[b::3]] | |
# Set Brightness of the strip. A brightness of 0 is the darkest and 255 is | |
# the brightest | |
def setMasterBrightness(self, brightness): | |
self._strip.setBrightness(brightness) | |
# Push new data | |
def update(self, data): | |
# handle channel order and gamma correction | |
self._fixData(data) | |
pixels = [tuple(data[(p * 3):(p * 3) + 3]) | |
for p in range(len(data) / 3)] | |
for i in range(len(data) / 3): | |
self._strip.setPixelColor( | |
i, Color(pixels[i][0], pixels[i][1], pixels[i][2])) | |
self._strip.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment