Class DLights


  • public class DLights
    extends java.lang.Object
    The DLights class drives up to four dLights on a single sensor port.

    The dLight is a RGB color LED connected to a sensor port. Up to four dLights can be daisy chained on a single port. The individual dLights are identified within this class by a sequence number (1-4). All dLights can be addressed simultaniously as a group by using sequence number 0.

    The DLights class supports two different color schemes for instructing the dLights; RGB and HSL. It supports just RGB for querying the dLights

    Author:
    Aswin Bouwmeester
    • Constructor Summary

      Constructors 
      Constructor Description
      DLights​(I2CPort port)
      Constructor for DLights.
      DLights​(Port port)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void disable​(int lightNo)
      Disables the dLight.
      void disableBlinking​(int lightNo)
      Disables blinking.
      void enable​(int lightNo)
      Enables the dLight.
      void enableBlinking​(int lightNo)
      Enables blinking pattern.
      void getColor​(int lightNo, int[] rgb)
      Returns the RGB color of the LED Each of the color values is between 0 (fully off) and 255 (fully on).
      DLight getDLight​(int lightNo)
      Returns the I2C driver for a single dLight.
      int getExternalLED​(int lightNo)
      Gets the PWM value of the external LED driver of the dLight.
      boolean isBlinkingEnabled​(int lightNo)
      Queries the blinking status of the dLight
      boolean isEnabled​(int lightNo)
      Queries the status of the dLight
      void setBlinkingPattern​(int lightNo, float seconds, int percentageOn)
      Specifies the blinking pattern of the LED.
      void setColor​(int lightNo, int[] rgb)
      Changes the color of the LED according to specified RGB color.
      void setColor​(int lightNo, int red, int green, int blue)
      Changes the color of the LED according to specified RGB color.
      void setExternalLED​(int lightNo, int value)
      Sets the PWM value of the external LED driver of the dLight.
      void setHSLColor​(int lightNo, int hue, int saturation, int luminosity)
      Changes the color of the LED according to specified HSL color.
      • Methods inherited from class java.lang.Object

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

      • DLights

        public DLights​(I2CPort port)
        Constructor for DLights.

        Nb. It also enables HIGH-SPEED I2C on this port.

        Parameters:
        port - The I2CPort that the dLights are attached to.
      • DLights

        public DLights​(Port port)
    • Method Detail

      • getDLight

        public DLight getDLight​(int lightNo)
        Returns the I2C driver for a single dLight.

        Nb. For ordinary use there is no need to use the I2C driver for a single dLight that this method returns. The method and the DLight instance it returns are nly useful if one needs to access the dLight directly over I2C.

        Parameters:
        lightNo - The sequence number of the dLight (1-4). Please note that the group number 0 is invalid for this method.
        Returns:
        the I2C driver for a single dLight
      • enable

        public void enable​(int lightNo)
        Enables the dLight.

        Parameters:
        lightNo - The sequence number of the dLight (0-4).
      • disable

        public void disable​(int lightNo)
        Disables the dLight. The light will be off, no matter what values for color are sent to the dLight.

        Values for color and blinking pattern are not overwritten and will still be in effect after enabling the dLight again.

        Parameters:
        lightNo - The sequence number of the dLight (0-4).
      • isEnabled

        public boolean isEnabled​(int lightNo)
        Queries the status of the dLight
        Parameters:
        lightNo - (1-4). Please note that the group number 0 is invalid for this method.
        Returns:
        True, the dLight is enabled. False, the dLight is off.
      • setColor

        public void setColor​(int lightNo,
                             int red,
                             int green,
                             int blue)
        Changes the color of the LED according to specified RGB color. Each of the color values should be between 0 (fully off) and 255 (fully on).
        Parameters:
        lightNo - The sequence number of the dLight (0-4).
        red -
        green -
        blue -
      • setColor

        public void setColor​(int lightNo,
                             int[] rgb)
        Changes the color of the LED according to specified RGB color. Each of the color values should be between 0 (fully off) and 255 (fully on).
        Parameters:
        lightNo - The sequence number of the dLight (0-4).
        rgb - an integer array containing RGB colors
      • setHSLColor

        public void setHSLColor​(int lightNo,
                                int hue,
                                int saturation,
                                int luminosity)
        Changes the color of the LED according to specified HSL color.
        Parameters:
        hue - The hue value in the range of 0-360
        saturation - The saturation value in the range of 0-100
        luminosity - The saturation luminosity value in the range of 0-100
      • setBlinkingPattern

        public void setBlinkingPattern​(int lightNo,
                                       float seconds,
                                       int percentageOn)
        Specifies the blinking pattern of the LED. Blinnking mode should be enabled for the pattern to be in effect.
        Parameters:
        lightNo - The sequence number of the dLight (0-4).
        seconds - The total time of a blinking cycle (in seconds)
        percentageOn - The percentage of the time the LED is on within a blinking cycle
      • enableBlinking

        public void enableBlinking​(int lightNo)
        Enables blinking pattern. The blinking pattern should be set with the SetBlinkingPattern method.
        Parameters:
        lightNo - The sequence number of the dLight (0-4).
      • disableBlinking

        public void disableBlinking​(int lightNo)
        Disables blinking. The blinking pattern itself remains in memory.
        Parameters:
        lightNo - The sequence number of the dLight (0-4).
      • isBlinkingEnabled

        public boolean isBlinkingEnabled​(int lightNo)
        Queries the blinking status of the dLight
        Parameters:
        lightNo - (1-4). Please note that the group number 0 is invalid for this method.
        Returns:
        True, blinking is enabled. False, blinking is disabled.
      • getColor

        public void getColor​(int lightNo,
                             int[] rgb)
        Returns the RGB color of the LED Each of the color values is between 0 (fully off) and 255 (fully on).
        Parameters:
        lightNo - The sequence number of the dLight (1-4). Please note that the group number 0 is invalid for this method.
        rgb - the RGB color of the LED
      • setExternalLED

        public void setExternalLED​(int lightNo,
                                   int value)
        Sets the PWM value of the external LED driver of the dLight. Each dLight has two leads broken out that can be used to drive an external LED.
        Parameters:
        lightNo - The sequence number of the dLight (0-4).
        value - The values should be between 0 (fully off) and 255 (fully on).
      • getExternalLED

        public int getExternalLED​(int lightNo)
        Gets the PWM value of the external LED driver of the dLight. Each dLight has two leads broken out that can be used to drive an external LED.
        Parameters:
        lightNo - The sequence number of the dLight (1-4). Please note that the group number 0 is invalid for this method.
        Returns:
        The return value is between 0 (fully off) and 255 (fully on).