grove.grove_ws2813_rgb_led_strip

This is the code for

Examples

import time
from rpi_ws281x import Color
from grove.grove_ws2813_rgb_led_strip import GroveWS2813RgbStrip

# connect to pin 12(slot PWM)
PIN   = 12
# For Grove - WS2813 RGB LED Strip Waterproof - 30 LED/m
# there is 30 RGB LEDs.
COUNT = 30
strip = GroveWS2813RgbStrip(PIN, COUNT)

# Define functions which animate LEDs in various ways.
def colorWipe(strip, color, wait_ms=50):
    """Wipe color across display a pixel at a time."""
    for i in range(strip.numPixels()):
        strip.setPixelColor(i, color)
        strip.show()
        time.sleep(wait_ms/1000.0)

print ('Color wipe animations.')
colorWipe(strip, Color(255, 0, 0))  # Red wipe
colorWipe(strip, Color(0, 255, 0))  # Blue wipe
colorWipe(strip, Color(0, 0, 255))  # Green wipe

Functions

  • Color(): Convert the provided red, green, blue color to a 24-bit color value.

grove.grove_ws2813_rgb_led_strip.Color(red, green, blue, white=0)[source]

Convert the provided red, green, blue color to a 24-bit color value. Each color component should be a value 0-255 where 0 is the lowest intensity and 255 is the highest intensity.

Classes

class grove.grove_ws2813_rgb_led_strip.GroveWS2813RgbStrip(pin, count, brightness=None)[source]

Wrapper Class for Grove - WS2813 RGB LED Strip Waterproof - XXX LED/m

Parameters:
  • pin (int) – 12, 18 for RPi

  • count (int) – strip LEDs count

  • brightness (int) – optional, set to 0 for darkest and 255 for brightest, default 255

Inheritance

digraph inheritancee21de5d975 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "GroveWS2813RgbStrip" [URL="#grove.grove_ws2813_rgb_led_strip.GroveWS2813RgbStrip",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Wrapper Class for Grove - WS2813 RGB LED Strip Waterproof - XXX LED/m"]; "PixelStrip" -> "GroveWS2813RgbStrip" [arrowsize=0.5,style="setlinewidth(0.5)"]; "PixelStrip" [URL="#grove.grove_ws2813_rgb_led_strip.PixelStrip",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }
class grove.grove_ws2813_rgb_led_strip.PixelStrip(num, pin, freq_hz=800000, dma=10, invert=False, brightness=255, channel=0, strip_type=None, gamma=None)[source]

Inheritance

digraph inheritanceeb085f3421 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "PixelStrip" [URL="#grove.grove_ws2813_rgb_led_strip.PixelStrip",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }
__getitem__(pos)[source]

Return the 24-bit RGB color value at the provided position or slice of positions.

__init__(num, pin, freq_hz=800000, dma=10, invert=False, brightness=255, channel=0, strip_type=None, gamma=None)[source]

Class to represent a SK6812/WS281x LED display. Num should be the number of pixels in the display, and pin should be the GPIO pin connected to the display signal line (must be a PWM pin like 18!). Optional parameters are freq, the frequency of the display signal in hertz (default 800khz), dma, the DMA channel to use (default 10), invert, a boolean specifying if the signal line should be inverted (default False), and channel, the PWM channel to use (defaults to 0).

__setitem__(pos, value)[source]

Set the 24-bit RGB color value at the provided position or slice of positions.

begin()[source]

Initialize library, must be called once before other functions are called.

getPixelColor(n)[source]

Get the 24-bit RGB color value for the LED at position n.

getPixels()[source]

Return an object which allows access to the LED display data as if it were a sequence of 24-bit RGB values.

numPixels()[source]

Return the number of pixels in the display.

setBrightness(brightness)[source]

Scale each LED in the buffer by the provided brightness. A brightness of 0 is the darkest and 255 is the brightest.

setPixelColor(n, color)[source]

Set LED at position n to the provided 24-bit color value (in RGB order).

setPixelColorRGB(n, red, green, blue, white=0)[source]

Set LED at position n to the provided red, green, and blue color. Each color component should be a value from 0 to 255 (where 0 is the lowest intensity and 255 is the highest intensity).

show()[source]

Update the display with the data from the LED buffer.