def hostStateInit(self): self.anim = RgbPixelsAnimation(self.graph, self.uri, self.updateOutput) log.debug('%s maxIndex = %s', self.uri, self.anim.maxIndex()) self.neo = rpi_ws281x.Adafruit_NeoPixel(self.anim.maxIndex() + 1, pin=18) self.neo.begin() colorOrder, stripType = self.anim.getColorOrder(self.graph, self.uri)
def __init__(self, led_count=1, led_pin=18, led_freq_hz=800000, led_dma=10, led_invert=False, led_brightness=100, led_channel=0): """Connect to Raspberry Pi and initilize the GPIO pins. Args: led_count (int): Number of leds in the led strip. led_pin (int): GPIO pin connected to the pixels (18 uses PWM!). led_freq_hz (int): (Optional) LED signal frequency in hertz (usually 800khz). led_dma (int): (Optional) DMA channel to use for generating signal (try 10). led_invert (bool): (Optional) True to invert the signal (when using NPN transistor level shift). led_brightness (int): (Optional) LED signal frequency in hertz (usually 800khz). led_channel (int): (Optional) set to '1' for GPIOs 13, 19, 41, 45 or 53. """ self.strip = neopixel.Adafruit_NeoPixel(led_count, led_pin, led_freq_hz, led_dma, led_invert, led_brightness, led_channel) self.strip.begin()
def __init__(self): # LED ring configuration: LED_COUNT = 16 # Number of LED pixels. LED_PIN = 10 # GPIO pin connected to the pixels (10: SPI, 18: PWM (used for sound). LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz) LED_DMA = 10 # DMA channel to use for generating signal (try 10) LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest LED_INVERT = False # True to invert the signal (when using NPN transistor level shift) LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53 self.LED_COUNT = LED_COUNT self.LED_OFFSET = 12 self.brightness = 1 self.monochrome = False self.controller = rpi_ws281x.Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) try: self.controller.begin() self.initialized = True except RuntimeError: # could not connect to led ring self.initialized = False
def open(self, num_pixels, datapin=18, order='rgb'): """ Open the device :param num_pixels: Total number of pixes on the strip/string :param datapin: Must be a pin that supports PWM. Pin 18 is the only pin on the RPi that supports PWM. :param order: Required for interface compatibility. Not used. :return: """ # Select strip type st = rpi_ws281x.WS2811_STRIP_RGB # default order = order.lower() # WS2811 string types if order == "grb": st = rpi_ws281x.WS2811_STRIP_GRB elif order == "rbg": st = rpi_ws281x.WS2811_STRIP_RBG elif order == "gbr": st = rpi_ws281x.WS2811_STRIP_GBR elif order == "brg": st = rpi_ws281x.WS2811_STRIP_BRG elif order == "bgr": st = rpi_ws281x.WS2811_STRIP_BGR self._strip = rpi_ws281x.Adafruit_NeoPixel(num_pixels, datapin, dma=10, strip_type=st) # print(self._strip) self._numpixels = num_pixels self._datapin = datapin return self._begin()
def __init__(self) -> None: self.brightness = 1.0 self.monochrome = False try: import rpi_ws281x except ModuleNotFoundError: self.initialized = False return self.controller = rpi_ws281x.Adafruit_NeoPixel( self.LED_COUNT, self.LED_PIN, self.LED_FREQ_HZ, self.LED_DMA, self.LED_INVERT, self.LED_BRIGHTNESS, self.LED_CHANNEL, ) try: self.controller.begin() self.initialized = True except RuntimeError: # could not connect to led ring self.initialized = False
def __init__( self, num_leds=8, led_pin=18, led_brightness=255, led_freq=800000, led_dma=10, led_channel=0, led_invert=False, ): """ Initialize a NeoPixel device. Arguments: num_leds: Number of LEDs on the device led_pin: GPIO pin connected to the pixels. 18 uses PWM, while 10 uses SPI /dev/spidev0.0 led_brightness: Set to 0 for darkest and 255 for brightest. led_freq: LED signal frequency in Hz (usually 800 khz) led_dma: DMA channel to use for generating signal. Try 10, and avoid 5 (as 5 may brick a RPi 3!). led_channel: Set to 1 for GPIOs 13, 19, 41, 45, or 53 led_invert: Whether to invert the signal. Useful when using an NPN transistor level shift. """ import rpi_ws281x as ws strip = ws.Adafruit_NeoPixel( num_leds, led_pin, led_freq, led_dma, led_invert, led_brightness, led_channel ) self.strip = strip try: self.strip.begin() except RuntimeError: raise RuntimeError( 'Could not initiate control of the LED device. ' 'Make sure the program is run with privileged permissions!' )
def __init__(self): Display.__init__(self) self.strip = rpi_ws281x.Adafruit_NeoPixel( self.LED_COUNT, self.LED_PIN, self.LED_FREQ_HZ, self.LED_DMA, self.LED_INVERT, self.LED_BRIGHTNESS, ) # Intialize the library (must be called once before other functions). self.strip.begin()
def __init__(self, log_warning): self.stop_rainbow = True self.log_warning = log_warning self.strip = neopixel.Adafruit_NeoPixel(self.LED_COUNT, self.LED_PIN, self.LED_FREQ_HZ, self.LED_DMA, self.LED_INVERT, self.LED_BRIGHTNESS, self.LED_CHANNEL) self.strip.begin() self.color('off')
def draw(self): """ Draw the leds in a loop, blocks """ strip = ws.Adafruit_NeoPixel(self.count, 18, 800000, 10, False, brightness) strip.begin() try: while True: self.update() self.internal_draw(strip) strip.show() time.sleep(update_rate) except KeyboardInterrupt: for x in range(self.count): strip.setPixelColor(x, 0) strip.show() time.sleep(1.0 / 50.0)
def make_strip(cfg, led_count): ''' return either a NoStrip or an Adafruit Strip based on if we are running on a Raspberry Pi or else ''' if os.path.isfile('/sys/firmware/devicetree/base/model'): # we are on a pi import rpi_ws281x as np # pragma: no cover pylint: ignore import-error ret = np.Adafruit_NeoPixel(led_count, cfg.getint("general", "led_pin"), cfg.getint("general", "led_freq"), cfg.getint("general", "led_dma"), cfg.getboolean("general", "led_invert"), cfg.getint("general", "brightness"), cfg.getint("general", "led_channel"), np.ws.WS2811_STRIP_GRB) else: ret = NoStrip(led_count, size_x=32, size_y=9) return ret
def __init__(self, led_count, led_pin, led_freq_hz, led_dma, led_invert, led_brightness, led_msg_queue): super().__init__() self.led_count = led_count # Neopixel strip initialisation. self.strip = rpi_ws281x.Adafruit_NeoPixel(led_count, led_pin, led_freq_hz, led_dma, led_invert, led_brightness, gamma=gamma8) # Initialise the library (must be called once before other functions). self.strip.begin() self.led_msg_queue = led_msg_queue # create the colours to be used for the bar graph, spread evenly over hte total pixels low_colour = 0 full_colour = 0.4 colour_step = float((full_colour - low_colour) / self.led_count) hue = full_colour # start the hue at full as we count down. self.rgb_colour_list = [] # Create the colour mapping to use. Red at the bottom (empty), green at the top (full). for colour in range(0, self.led_count): hue = hue - colour_step if hue < low_colour: hue = low_colour rgb_colour = colorsys.hsv_to_rgb(hue, 1, 0.5) rgb_colour = [int(element * 255) for element in rgb_colour] #print(hue, rgb_colour) self.rgb_colour_list.append(rpi_ws281x.Color(*tuple(rgb_colour)))
def __init__(self, n_pixels=100, led_pin=18, led_freq_hz=800000, led_dma=5, brightness=255, led_invert=False, software_gamma_correction=True, gamma_table_path=None): self.N_PIXELS = n_pixels self.LED_PIN = led_pin self.LED_FREQ_HZ = led_freq_hz self.LED_DMA = led_dma self.LED_INVERT = led_invert self.BRIGHTNESS = brightness self.SOFTWARE_GAMMA_CORRECTION = software_gamma_correction if gamma_table_path: self.GAMMA_TABLE_PATH = gamma_table_path else: self.GAMMA_TABLE_PATH = os.path.join(os.path.dirname(__file__), 'gamma_table.npy') self.strip = neopixel.Adafruit_NeoPixel(self.N_PIXELS, self.LED_PIN, self.LED_FREQ_HZ, self.LED_DMA, self.LED_INVERT, self.BRIGHTNESS) self.strip.begin() self._gamma = np.load(self.GAMMA_TABLE_PATH) """Gamma lookup table used for nonlinear brightness correction""" self._prev_pixels = np.tile(253, (3, self.N_PIXELS)) """Pixel values that were most recently displayed on the LED strip""" self.pixels = np.tile(1, (3, self.N_PIXELS)) """Pixel values for the LED strip"""
def __init__(self): self.log = logging.getLogger("client") self.strip = npx.Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) self.strip.begin() self.in_queue = queue.PriorityQueue() self.out_queue = queue.Queue() self.beat_flag = threading.Event() self.animation_process = None self.brightness = multiprocessing.Event() self.beat_flag.set() GPIO.add_event_detect( BEAT_PIN, GPIO.RISING, callback=self.beat_callback, bouncetime=10 ) self.strip.setBrightness(0) time.sleep(1) self.strip.setBrightness(1)
def __init__(self, manager) -> None: super().__init__(manager, "ring") try: import rpi_ws281x except ModuleNotFoundError: return self.controller = rpi_ws281x.Adafruit_NeoPixel( self.LED_COUNT, self.LED_PIN, self.LED_FREQ_HZ, self.LED_DMA, self.LED_INVERT, self.LED_BRIGHTNESS, self.LED_CHANNEL, ) try: self.controller.begin() self.initialized = True redis.put("ring_initialized", True) except RuntimeError: # could not connect to led ring return
for i in range(0, strip.numPixels(), 3): strip.setPixelColor(i + q, 0) # Main program logic follows: if __name__ == '__main__': # Process arguments parser = argparse.ArgumentParser() parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit') args = parser.parse_args() # Create NeoPixel object with appropriate configuration. strip = r.Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) # Intialize the library (must be called once before other functions). strip.begin() print('Press Ctrl-C to quit.') if not args.clear: print('Use "-c" argument to clear LEDs on exit') try: while True: print('Color wipe animations.') colorWipe(strip, r.Color(255, 0, 0)) # Red wipe colorWipe(strip, r.Color(0, 255, 0)) # Blue wipe colorWipe(strip, r.Color(0, 0, 255)) # Green wipe print('Theater chase animations.')
from __future__ import print_function from __future__ import division import platform import numpy as np import config # Raspberry Pi controls the LED strip directly import rpi_ws281x as neopixel strip = neopixel.Adafruit_NeoPixel(config.N_PIXELS, config.LED_PIN, config.LED_FREQ_HZ, config.LED_DMA, config.LED_INVERT, config.BRIGHTNESS) strip.begin() stick = blinkstick.find_first() # Create a listener that turns the leds off when the program terminates signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGINT, signal_handler) _gamma = np.load(config.GAMMA_TABLE_PATH) """Gamma lookup table used for nonlinear brightness correction""" _prev_pixels = np.tile(253, (3, config.N_PIXELS)) """Pixel values that were most recently displayed on the LED strip""" pixels = np.tile(1, (3, config.N_PIXELS)) """Pixel values for the LED strip""" _is_python_2 = int(platform.python_version_tuple()[0]) == 2
import random import board import rpi_ws281x import time import math #WS2812 (NeoPixel) setup NO_LEDS = 29 #defines the number of LEDs in the chain LED_PIN = 18 #the BCM pin the LEDs are connected to LED_FREQ_HZ = 800000 LED_DMA = 10 LED_BRIGHTNESS = 255 LED_INVERT = False LED_CHANNEL = 0 pixels = rpi_ws281x.Adafruit_NeoPixel(NO_LEDS, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) pixels.begin() class Sphere: '''An object representing the dragon box's glowing ping pong balls''' def __init__(self, y, x, pix_pos, broken=False): self.broken = broken #must be set before colour as used by @colour.setter self.x = x #coordinate within the sphere layout self.y = y #coordinate within the sphere layout self.pix_pos = pix_pos #represents the WS2812 chain position for this sphere self.colour = (0, random.randint(25, 200), 0) #initially set up for flame mode, a random colour so they don't all start out the same self.flame_target = random.randint(25, 200) self.flicker_speed = 0.5 #can adjust the speed of the flame animation
#unicornhat.set_layout(unicornhat.PHAT) #unicornhat.set_pixel(0, 0, 255, 255, 255) #unicornhat.set_pixel(0, 1, 255, 255, 255) #unicornhat.set_pixel(0, 2, 255, 255, 255) #unicornhat.set_pixel(0, 3, 255, 255, 255) # LED strip configuration: LED_COUNT = 180 # Number of LED pixels. LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!). LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz) LED_DMA = 5 # DMA channel to use for generating signal (try 5) LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest LED_INVERT = False # True to invert the signal (when using NPN transistor level shift) # Create NeoPixel object with appropriate configuration. strip = rpi_ws281x.Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS) # Intialize the library (must be called once before other functions). strip.begin() for i in range(strip.numPixels()): # Green Red Blue strip.setPixelColor(i, rpi_ws281x.Color(0, 0, 0)) strip.show() #unicornhat.show() try: print("Press Ctrl-C to finish") # Keep cycling through various colours - assume the user will press Control-C to finish.
def make(): strip = r.Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) strip.begin() return strip
def __init__(self, led_count, led_pin, led_freq_hz, led_dma, led_invert, led_brightness): self.strip = rpi_ws281x.Adafruit_NeoPixel(led_count, led_pin, led_freq_hz, led_dma, led_invert, led_brightness, gamma= gamma8) # Intialize the library (must be called once before other functions). self.strip.begin()
class StripeFactory(object): def create_stripe(self, (width, height), brightness): stripe = rpi_ws281x.Adafruit_NeoPixel(width * height, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, brightness) return stripe