Class DLights
- java.lang.Object
-
- lejos.hardware.device.DLights
-
public class DLights extends java.lang.ObjectThe 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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddisable(int lightNo)Disables the dLight.voiddisableBlinking(int lightNo)Disables blinking.voidenable(int lightNo)Enables the dLight.voidenableBlinking(int lightNo)Enables blinking pattern.voidgetColor(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).DLightgetDLight(int lightNo)Returns the I2C driver for a single dLight.intgetExternalLED(int lightNo)Gets the PWM value of the external LED driver of the dLight.booleanisBlinkingEnabled(int lightNo)Queries the blinking status of the dLightbooleanisEnabled(int lightNo)Queries the status of the dLightvoidsetBlinkingPattern(int lightNo, float seconds, int percentageOn)Specifies the blinking pattern of the LED.voidsetColor(int lightNo, int[] rgb)Changes the color of the LED according to specified RGB color.voidsetColor(int lightNo, int red, int green, int blue)Changes the color of the LED according to specified RGB color.voidsetExternalLED(int lightNo, int value)Sets the PWM value of the external LED driver of the dLight.voidsetHSLColor(int lightNo, int hue, int saturation, int luminosity)Changes the color of the LED according to specified HSL color.
-
-
-
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-360saturation- The saturation value in the range of 0-100luminosity- 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).
-
-