Class Ws281xLedStrip

java.lang.Object
com.github.mbelling.ws281x.Ws281xLedStrip
All Implemented Interfaces:
LedStrip

public class Ws281xLedStrip extends Object implements LedStrip
Basic class to interface with the rpi_ws281x native library
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor with the following settings: ledCount = 100 gpioPin = 18 frequenchHz = 800000 dma = 10 brightness = 255 pwmChannel = 0 invert = false stripType = WS2811_STRIP_RGB
    Ws281xLedStrip(int ledsCount, int gpioPin, int frequencyHz, int dma, boolean invert, LedStripType stripType, boolean clearOnExit)
    Create an LED strip with the given settings
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Get the current brightness value of the strip
    int
     
    int
     
    int
     
    int
    Get the number of LEDs in this strip
    long
    getPixel(int pixel)
    Get the color of a pixel
    int
     
     
    boolean
     
    void
    Render the current values to the physical light strip.
    void
    setBrightness(int brightness)
    Set the brightness value from 0-255
    void
    setPixel(int pixel, int red, int green, int blue)
    Set the color of an individual pixel
    void
    setPixel(int pixel, Color color)
    Set the color of an individual pixel
    void
    setStrip(int red, int green, int blue)
    Set all LEDs in the strip to one color
    void
    setStrip(Color color)
    Set all LEDs in the strip to one color

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Ws281xLedStrip

      public Ws281xLedStrip()
      Default constructor with the following settings:
      • ledCount = 100
      • gpioPin = 18
      • frequenchHz = 800000
      • dma = 10
      • brightness = 255
      • pwmChannel = 0
      • invert = false
      • stripType = WS2811_STRIP_RGB
      See Also:
    • Ws281xLedStrip

      public Ws281xLedStrip(int ledsCount, int gpioPin, int frequencyHz, int dma, boolean invert, LedStripType stripType, boolean clearOnExit)
      Create an LED strip with the given settings
      Parameters:
      ledsCount - The number of LEDs in the strip
      gpioPin - The Raspberry Pi GPIO pin
      frequencyHz - Frequency of updates in Hertz
      dma - DMA to use
      invert - Whether or not to invert color values
      stripType - The type of LED Strip rpi_ws281xConstants
      clearOnExit - Clear LEDs on exit
  • Method Details

    • setPixel

      public void setPixel(int pixel, int red, int green, int blue)
      Set the color of an individual pixel
      Specified by:
      setPixel in interface LedStrip
      Parameters:
      pixel - The index of the pixel in the strip
      red - The red value (0 - 255)
      green - The green value (0 - 255)
      blue - The blue value (0 - 255)
    • setPixel

      public void setPixel(int pixel, Color color)
      Set the color of an individual pixel
      Specified by:
      setPixel in interface LedStrip
      Parameters:
      pixel - The index of the pixel in the strip
      color - The color to set on the pixel
    • setStrip

      public void setStrip(int red, int green, int blue)
      Set all LEDs in the strip to one color
      Specified by:
      setStrip in interface LedStrip
      Parameters:
      red - The red value (0 - 255)
      green - The green value (0 - 255)
      blue - The blue value (0 - 255)
    • setStrip

      public void setStrip(Color color)
      Set all LEDs in the strip to one color
      Specified by:
      setStrip in interface LedStrip
      Parameters:
      color - The color to set on the strip
    • getPixel

      public long getPixel(int pixel)
      Get the color of a pixel
      Specified by:
      getPixel in interface LedStrip
      Parameters:
      pixel - the index of the pixel
      Returns:
      The color of the pixel as a long
    • render

      public void render()
      Render the current values to the physical light strip.

      This method needs to be called after any previous setPixel calls to make the lights change to those colors.

      Specified by:
      render in interface LedStrip
    • setBrightness

      public void setBrightness(int brightness)
      Description copied from interface: LedStrip
      Set the brightness value from 0-255
      Specified by:
      setBrightness in interface LedStrip
      Parameters:
      brightness - The brightnes to set the strip to
    • getLedsCount

      public int getLedsCount()
      Description copied from interface: LedStrip
      Get the number of LEDs in this strip
      Specified by:
      getLedsCount in interface LedStrip
      Returns:
      The number of LEDs
    • getGpioPin

      public int getGpioPin()
    • getFrequencyHz

      public int getFrequencyHz()
    • getDma

      public int getDma()
    • getBrightness

      public int getBrightness()
      Description copied from interface: LedStrip
      Get the current brightness value of the strip
      Specified by:
      getBrightness in interface LedStrip
      Returns:
      The current brightness value
    • getPwmChannel

      public int getPwmChannel()
    • isInvert

      public boolean isInvert()
    • getStripType

      public LedStripType getStripType()