Package com.diozero.ws281xj.rpiws281x
Class WS281x
- java.lang.Object
-
- com.diozero.ws281xj.rpiws281x.WS281x
-
- All Implemented Interfaces:
LedDriverInterface
,AutoCloseable
public class WS281x extends 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
allOff()
Turn off all pixels and render.void
close()
int
getNumPixels()
int
getPixelColour(int pixel)
Get the current colour for the specified pixel.void
render()
Push any updated colours to the LED strip.void
setPixelColour(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, wait
-
Methods inherited from interface com.diozero.ws281xj.LedDriverInterface
getBlueComponent, getGreenComponent, getRedComponent, setBlueComponent, setGreenComponent, setPixelColourHSB, setPixelColourHSL, setPixelColourRGB, setRedComponent
-
-
-
-
Constructor Detail
-
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 Detail
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceLedDriverInterface
-
getNumPixels
public int getNumPixels()
- Specified by:
getNumPixels
in interfaceLedDriverInterface
-
render
public void render()
Description copied from interface:LedDriverInterface
Push any updated colours to the LED strip.- Specified by:
render
in interfaceLedDriverInterface
-
allOff
public void allOff()
Description copied from interface:LedDriverInterface
Turn off all pixels and render.- Specified by:
allOff
in interfaceLedDriverInterface
-
getPixelColour
public int getPixelColour(int pixel)
Description copied from interface:LedDriverInterface
Get the current colour for the specified pixel.- Specified by:
getPixelColour
in interfaceLedDriverInterface
- Parameters:
pixel
- Pixel number.- Returns:
- 24-bit RGB colour value.
-
setPixelColour
public void setPixelColour(int pixel, int colour)
Description copied from interface:LedDriverInterface
Set the colour for the specified pixel.- Specified by:
setPixelColour
in interfaceLedDriverInterface
- Parameters:
pixel
- Pixel number.colour
- Colour represented as a 24bit RGB integer (0x0RGB).
-
-