Package com.diozero.ws281xj.rpiws281x
Class WS281x
java.lang.Object
com.diozero.ws281xj.rpiws281x.WS281x
- All Implemented Interfaces:
LedDriverInterface,java.io.Closeable,java.lang.AutoCloseable
public class WS281x extends java.lang.Object implements LedDriverInterface
Provides support for WS2811B / WS2812B aka Adafriut NeoPixel LEDs via a JNI wrapper around the rpi_ws281x C library.
Also see this implementation.
All colours are represented as 24bit RGB values.
Valid GPIO numbers:
- 12 / 18 (PWM)
- 21 / 31 (PCM)
- 10 (SPI)
-
Constructor Summary
Constructors Constructor Description WS281x(int gpioNum, int brightness, int numPixels)WS281x(int frequency, int dmaNum, int gpioNum, int brightness, int numPixels, StripType stripType)WS281x(int frequency, int dmaNum, int gpioNum, int brightness, int numPixels, StripType stripType, int channel) -
Method Summary
Modifier and Type Method Description voidallOff()Turn off all pixels and render.voidclose()intgetNumPixels()intgetPixelColour(int pixel)Get the current colour for the specified pixel.voidrender()Push any updated colours to the LED strip.voidsetPixelColour(int pixel, int colour)Set the colour for the specified pixel.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.diozero.ws281xj.LedDriverInterface
getBlueComponent, getGreenComponent, getRedComponent, setBlueComponent, setGreenComponent, setPixelColourHSB, setPixelColourHSL, setPixelColourRGB, setRedComponent
-
Constructor Details
-
WS281x
public WS281x(int gpioNum, int brightness, int numPixels)- Parameters:
gpioNum- GPIO pin to use to drive the LEDs.brightness- Brightness level (0..255).numPixels- The number of pixels connected.
-
WS281x
public WS281x(int frequency, int dmaNum, int gpioNum, int brightness, int numPixels, StripType stripType)- Parameters:
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.stripType- Strip type
-
WS281x
public WS281x(int frequency, int dmaNum, int gpioNum, int brightness, int numPixels, StripType stripType, int channel)- Parameters:
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.stripType- Strip typechannel- PWM channel
-
-
Method Details
-
close
public void close()- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceLedDriverInterface
-
getNumPixels
public int getNumPixels()- Specified by:
getNumPixelsin interfaceLedDriverInterface
-
render
public void render()Description copied from interface:LedDriverInterfacePush any updated colours to the LED strip.- Specified by:
renderin interfaceLedDriverInterface
-
allOff
public void allOff()Description copied from interface:LedDriverInterfaceTurn off all pixels and render.- Specified by:
allOffin interfaceLedDriverInterface
-
getPixelColour
public int getPixelColour(int pixel)Description copied from interface:LedDriverInterfaceGet the current colour for the specified pixel.- Specified by:
getPixelColourin interfaceLedDriverInterface- Parameters:
pixel- Pixel number.- Returns:
- 24-bit RGB colour value.
-
setPixelColour
public void setPixelColour(int pixel, int colour)Description copied from interface:LedDriverInterfaceSet the colour for the specified pixel.- Specified by:
setPixelColourin interfaceLedDriverInterface- Parameters:
pixel- Pixel number.colour- Colour represented as a 24bit RGB integer (0x0RGB).
-