public class WS281x extends Object implements Closeable
Provides support for WS2811B / WS2812B aka Adafriut NeoPixel LEDs via a JNI wrapper around the rpi_ws281x C library.
All colours are represented as 24bit RGB values.
| Constructor and Description |
|---|
WS281x(int gpioNum,
int brightness,
int numPixels) |
WS281x(int frequency,
int dmaNum,
int gpioNum,
int brightness,
int numPixels) |
| Modifier and Type | Method and Description |
|---|---|
void |
allOff()
Turn off all pixels.
|
void |
close() |
int |
getBlueComponent(int pixel)
Get the 8-bit blue component value for the specified pixel.
|
int |
getGreenComponent(int pixel)
Get the 8-bit green component value for the specified pixel.
|
int |
getNumPixels() |
int |
getPixelColour(int pixel)
Get the current colour for the specified pixel.
|
int |
getRedComponent(int pixel)
Get the 8-bit red component value for the specified pixel.
|
void |
render()
Push any updated colours to the LED strip.
|
void |
setBlueComponent(int pixel,
int blue)
Set the 8-bit blue component value for the specified pixel.
|
void |
setGreenComponent(int pixel,
int green)
Set the 8-bit green component value for the specified pixel.
|
void |
setPixelColour(int pixel,
int colour)
Set the colour for the specified pixel.
|
void |
setPixelColourHSB(int pixel,
float hue,
float saturation,
float brightness)
Set the colour for the specified pixel using Hue Saturation Brightness (HSB) values.
|
void |
setPixelColourHSL(int pixel,
float hue,
float saturation,
float luminance)
Set the colour for the specified pixel using Hue Saturation Luminance (HSL) values.
|
void |
setPixelColourRGB(int pixel,
int red,
int green,
int blue)
Set the colour for the specified pixel using individual red / green / blue 8-bit values.
|
void |
setRedComponent(int pixel,
int red)
Set the 8-bit red component value for the specified pixel.
|
public WS281x(int gpioNum,
int brightness,
int numPixels)
gpioNum - GPIO pin to use to drive the LEDs.brightness - Brightness level (0..255).numPixels - The number of pixels connected.public WS281x(int frequency,
int dmaNum,
int gpioNum,
int brightness,
int numPixels)
frequency - Communication frequency, 800,000 or 400,000.dmaNum - DMA number.gpioNum - GPIO pin to use to drive the LEDs.brightness - Brightness level (0..255).numPixels - The number of pixels connected.public void close()
close in interface Closeableclose in interface AutoCloseablepublic int getNumPixels()
public void render()
public void allOff()
public int getPixelColour(int pixel)
pixel - Pixel number.public void setPixelColour(int pixel,
int colour)
pixel - Pixel number.colour - Colour represented as a 24bit RGB integer (0x0RGB).public void setPixelColourRGB(int pixel,
int red,
int green,
int blue)
pixel - Pixel number.red - 8-bit value for the red component.green - 8-bit value for the green component.blue - 8-bit value for the blue component.public void setPixelColourHSB(int pixel,
float hue,
float saturation,
float brightness)
pixel - Pixel number.hue - Float value in the range 0..1 representing the hue.saturation - Float value in the range 0..1 representing the colour saturation.brightness - Float value in the range 0..1 representing the colour brightness.public void setPixelColourHSL(int pixel,
float hue,
float saturation,
float luminance)
Set the colour for the specified pixel using Hue Saturation Luminance (HSL) values.
HSL colour mapping code taken from this HSL Color class by Rob Camick.
pixel - Pixel number.hue - Represents the colour (think colours of the rainbow), specified in degrees from 0 - 360. Red is 0, green is 120 and blue is 240.saturation - Represents the purity of the colour. Range is 0..1 with 1 fully saturated and 0 gray.luminance - Represents the brightness of the colour. Range is 0..1 with 1 white 0 black.public int getRedComponent(int pixel)
pixel - Pixel number.public void setRedComponent(int pixel,
int red)
pixel - Pixel number.red - 8-bit red component value.public int getGreenComponent(int pixel)
pixel - Pixel number.public void setGreenComponent(int pixel,
int green)
pixel - Pixel number.green - 8-bit green component value.public int getBlueComponent(int pixel)
pixel - Pixel number.public void setBlueComponent(int pixel,
int blue)
pixel - Pixel number.blue - 8-bit blue component value.Copyright © 2016 mattjlewis. All rights reserved.