Package com.tinkerforge
Class BrickletColor
- java.lang.Object
-
- com.tinkerforge.DeviceBase
-
- com.tinkerforge.Device
-
- com.tinkerforge.BrickletColor
-
public class BrickletColor extends Device
Measures color (RGB value), illuminance and color temperature
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BrickletColor.Color
class
BrickletColor.ColorCallbackThreshold
static interface
BrickletColor.ColorListener
This listener is triggered periodically with the period that is set bysetColorCallbackPeriod(long)
.static interface
BrickletColor.ColorReachedListener
This listener is triggered when the threshold as set bysetColorCallbackThreshold(char, int, int, int, int, int, int, int, int)
is reached.static interface
BrickletColor.ColorTemperatureListener
This listener is triggered periodically with the period that is set bysetColorTemperatureCallbackPeriod(long)
.class
BrickletColor.Config
static interface
BrickletColor.IlluminanceListener
This listener is triggered periodically with the period that is set bysetIlluminanceCallbackPeriod(long)
.-
Nested classes/interfaces inherited from class com.tinkerforge.Device
Device.Identity
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description BrickletColor(java.lang.String uid, IPConnection ipcon)
Creates an object with the unique device ID \c uid.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addColorListener(BrickletColor.ColorListener listener)
Adds a Color listener.void
addColorReachedListener(BrickletColor.ColorReachedListener listener)
Adds a ColorReached listener.void
addColorTemperatureListener(BrickletColor.ColorTemperatureListener listener)
Adds a ColorTemperature listener.void
addIlluminanceListener(BrickletColor.IlluminanceListener listener)
Adds a Illuminance listener.BrickletColor.Color
getColor()
Returns the measured color of the sensor.long
getColorCallbackPeriod()
Returns the period as set bysetColorCallbackPeriod(long)
.BrickletColor.ColorCallbackThreshold
getColorCallbackThreshold()
Returns the threshold as set bysetColorCallbackThreshold(char, int, int, int, int, int, int, int, int)
.int
getColorTemperature()
Returns the color temperature.long
getColorTemperatureCallbackPeriod()
Returns the period as set bysetColorTemperatureCallbackPeriod(long)
.BrickletColor.Config
getConfig()
Returns the configuration as set bysetConfig(short, short)
.long
getDebouncePeriod()
Returns the debounce period as set bysetDebouncePeriod(long)
.Device.Identity
getIdentity()
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.long
getIlluminance()
Returns the illuminance affected by the gain and integration time as set bysetConfig(short, short)
.long
getIlluminanceCallbackPeriod()
Returns the period as set bysetIlluminanceCallbackPeriod(long)
.short
isLightOn()
Returns the state of the LED.void
lightOff()
Turns the LED off.void
lightOn()
Turns the LED on.void
removeColorListener(BrickletColor.ColorListener listener)
Removes a Color listener.void
removeColorReachedListener(BrickletColor.ColorReachedListener listener)
Removes a ColorReached listener.void
removeColorTemperatureListener(BrickletColor.ColorTemperatureListener listener)
Removes a ColorTemperature listener.void
removeIlluminanceListener(BrickletColor.IlluminanceListener listener)
Removes a Illuminance listener.void
setColorCallbackPeriod(long period)
Sets the period with which theBrickletColor.ColorListener
listener is triggered periodically.void
setColorCallbackThreshold(char option, int minR, int maxR, int minG, int maxG, int minB, int maxB, int minC, int maxC)
Sets the thresholds for theBrickletColor.ColorReachedListener
listener.void
setColorTemperatureCallbackPeriod(long period)
Sets the period with which theBrickletColor.ColorTemperatureListener
listener is triggered periodically.void
setConfig(short gain, short integrationTime)
Sets the configuration of the sensor.void
setDebouncePeriod(long debounce)
Sets the period with which the threshold listener *BrickletColor.ColorReachedListener
is triggered, if the threshold *setColorCallbackThreshold(char, int, int, int, int, int, int, int, int)
keeps being reached.void
setIlluminanceCallbackPeriod(long period)
Sets the period with which theBrickletColor.IlluminanceListener
listener is triggered periodically.-
Methods inherited from class com.tinkerforge.DeviceBase
getAPIVersion, getResponseExpected, setResponseExpected, setResponseExpectedAll
-
-
-
-
Field Detail
-
DEVICE_IDENTIFIER
public static final int DEVICE_IDENTIFIER
- See Also:
- Constant Field Values
-
DEVICE_DISPLAY_NAME
public static final java.lang.String DEVICE_DISPLAY_NAME
- See Also:
- Constant Field Values
-
FUNCTION_GET_COLOR
public static final byte FUNCTION_GET_COLOR
- See Also:
- Constant Field Values
-
FUNCTION_SET_COLOR_CALLBACK_PERIOD
public static final byte FUNCTION_SET_COLOR_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_COLOR_CALLBACK_PERIOD
public static final byte FUNCTION_GET_COLOR_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_SET_COLOR_CALLBACK_THRESHOLD
public static final byte FUNCTION_SET_COLOR_CALLBACK_THRESHOLD
- See Also:
- Constant Field Values
-
FUNCTION_GET_COLOR_CALLBACK_THRESHOLD
public static final byte FUNCTION_GET_COLOR_CALLBACK_THRESHOLD
- See Also:
- Constant Field Values
-
FUNCTION_SET_DEBOUNCE_PERIOD
public static final byte FUNCTION_SET_DEBOUNCE_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_DEBOUNCE_PERIOD
public static final byte FUNCTION_GET_DEBOUNCE_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_LIGHT_ON
public static final byte FUNCTION_LIGHT_ON
- See Also:
- Constant Field Values
-
FUNCTION_LIGHT_OFF
public static final byte FUNCTION_LIGHT_OFF
- See Also:
- Constant Field Values
-
FUNCTION_IS_LIGHT_ON
public static final byte FUNCTION_IS_LIGHT_ON
- See Also:
- Constant Field Values
-
FUNCTION_SET_CONFIG
public static final byte FUNCTION_SET_CONFIG
- See Also:
- Constant Field Values
-
FUNCTION_GET_CONFIG
public static final byte FUNCTION_GET_CONFIG
- See Also:
- Constant Field Values
-
FUNCTION_GET_ILLUMINANCE
public static final byte FUNCTION_GET_ILLUMINANCE
- See Also:
- Constant Field Values
-
FUNCTION_GET_COLOR_TEMPERATURE
public static final byte FUNCTION_GET_COLOR_TEMPERATURE
- See Also:
- Constant Field Values
-
FUNCTION_SET_ILLUMINANCE_CALLBACK_PERIOD
public static final byte FUNCTION_SET_ILLUMINANCE_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_ILLUMINANCE_CALLBACK_PERIOD
public static final byte FUNCTION_GET_ILLUMINANCE_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_SET_COLOR_TEMPERATURE_CALLBACK_PERIOD
public static final byte FUNCTION_SET_COLOR_TEMPERATURE_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_COLOR_TEMPERATURE_CALLBACK_PERIOD
public static final byte FUNCTION_GET_COLOR_TEMPERATURE_CALLBACK_PERIOD
- See Also:
- Constant Field Values
-
FUNCTION_GET_IDENTITY
public static final byte FUNCTION_GET_IDENTITY
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_OFF
public static final char THRESHOLD_OPTION_OFF
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_OUTSIDE
public static final char THRESHOLD_OPTION_OUTSIDE
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_INSIDE
public static final char THRESHOLD_OPTION_INSIDE
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_SMALLER
public static final char THRESHOLD_OPTION_SMALLER
- See Also:
- Constant Field Values
-
THRESHOLD_OPTION_GREATER
public static final char THRESHOLD_OPTION_GREATER
- See Also:
- Constant Field Values
-
LIGHT_ON
public static final short LIGHT_ON
- See Also:
- Constant Field Values
-
LIGHT_OFF
public static final short LIGHT_OFF
- See Also:
- Constant Field Values
-
GAIN_1X
public static final short GAIN_1X
- See Also:
- Constant Field Values
-
GAIN_4X
public static final short GAIN_4X
- See Also:
- Constant Field Values
-
GAIN_16X
public static final short GAIN_16X
- See Also:
- Constant Field Values
-
GAIN_60X
public static final short GAIN_60X
- See Also:
- Constant Field Values
-
INTEGRATION_TIME_2MS
public static final short INTEGRATION_TIME_2MS
- See Also:
- Constant Field Values
-
INTEGRATION_TIME_24MS
public static final short INTEGRATION_TIME_24MS
- See Also:
- Constant Field Values
-
INTEGRATION_TIME_101MS
public static final short INTEGRATION_TIME_101MS
- See Also:
- Constant Field Values
-
INTEGRATION_TIME_154MS
public static final short INTEGRATION_TIME_154MS
- See Also:
- Constant Field Values
-
INTEGRATION_TIME_700MS
public static final short INTEGRATION_TIME_700MS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BrickletColor
public BrickletColor(java.lang.String uid, IPConnection ipcon)
Creates an object with the unique device ID \c uid. and adds it to the IP Connection \c ipcon.
-
-
Method Detail
-
getColor
public BrickletColor.Color getColor() throws TinkerforgeException
Returns the measured color of the sensor. The red (r), green (g), blue (b) and clear (c) colors are measured with four different photodiodes that are responsive at different wavelengths: .. image:: /Images/Bricklets/bricklet_color_wavelength_chart_600.jpg :scale: 100 % :alt: Chart Responsivity / Wavelength :align: center :target: ../../_images/Bricklets/bricklet_color_wavelength_chart_600.jpg If you want to get the color periodically, it is recommended to use theBrickletColor.ColorListener
listener and set the period withsetColorCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setColorCallbackPeriod
public void setColorCallbackPeriod(long period) throws TinkerforgeException
Sets the period with which theBrickletColor.ColorListener
listener is triggered periodically. A value of 0 turns the listener off. TheBrickletColor.ColorListener
listener is only triggered if the color has changed since the last triggering.- Throws:
TinkerforgeException
-
getColorCallbackPeriod
public long getColorCallbackPeriod() throws TinkerforgeException
Returns the period as set bysetColorCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setColorCallbackThreshold
public void setColorCallbackThreshold(char option, int minR, int maxR, int minG, int maxG, int minB, int maxB, int minC, int maxC) throws TinkerforgeException
Sets the thresholds for theBrickletColor.ColorReachedListener
listener. The following options are possible: \verbatim "Option", "Description" "'x'", "Listener is turned off" "'o'", "Listener is triggered when the temperature is *outside* the min and max values" "'i'", "Listener is triggered when the temperature is *inside* the min and max values" "'<'", "Listener is triggered when the temperature is smaller than the min value (max is ignored)" "'>'", "Listener is triggered when the temperature is greater than the min value (max is ignored)" \endverbatim- Throws:
TinkerforgeException
-
getColorCallbackThreshold
public BrickletColor.ColorCallbackThreshold getColorCallbackThreshold() throws TinkerforgeException
Returns the threshold as set bysetColorCallbackThreshold(char, int, int, int, int, int, int, int, int)
.- Throws:
TinkerforgeException
-
setDebouncePeriod
public void setDebouncePeriod(long debounce) throws TinkerforgeException
Sets the period with which the threshold listener *BrickletColor.ColorReachedListener
is triggered, if the threshold *setColorCallbackThreshold(char, int, int, int, int, int, int, int, int)
keeps being reached.- Throws:
TinkerforgeException
-
getDebouncePeriod
public long getDebouncePeriod() throws TinkerforgeException
Returns the debounce period as set bysetDebouncePeriod(long)
.- Throws:
TinkerforgeException
-
lightOn
public void lightOn() throws TinkerforgeException
Turns the LED on.- Throws:
TinkerforgeException
-
lightOff
public void lightOff() throws TinkerforgeException
Turns the LED off.- Throws:
TinkerforgeException
-
isLightOn
public short isLightOn() throws TinkerforgeException
Returns the state of the LED. Possible values are: * 0: On * 1: Off- Throws:
TinkerforgeException
-
setConfig
public void setConfig(short gain, short integrationTime) throws TinkerforgeException
Sets the configuration of the sensor. Gain and integration time can be configured in this way. For configuring the gain: * 0: 1x Gain * 1: 4x Gain * 2: 16x Gain * 3: 60x Gain For configuring the integration time: * 0: 2.4ms * 1: 24ms * 2: 101ms * 3: 154ms * 4: 700ms Increasing the gain enables the sensor to detect a color from a higher distance. The integration time provides a trade-off between conversion time and accuracy. With a longer integration time the values read will be more accurate but it will take longer time to get the conversion results.- Throws:
TinkerforgeException
-
getConfig
public BrickletColor.Config getConfig() throws TinkerforgeException
Returns the configuration as set bysetConfig(short, short)
.- Throws:
TinkerforgeException
-
getIlluminance
public long getIlluminance() throws TinkerforgeException
Returns the illuminance affected by the gain and integration time as set bysetConfig(short, short)
. To get the illuminance in Lux apply this formula:: lux = illuminance * 700 / gain / integration_time To get a correct illuminance measurement make sure that the color values themselves are not saturated. The color value (R, G or B) is saturated if it is equal to the maximum value of 65535. In that case you have to reduce the gain, seesetConfig(short, short)
.- Throws:
TinkerforgeException
-
getColorTemperature
public int getColorTemperature() throws TinkerforgeException
Returns the color temperature. To get a correct color temperature measurement make sure that the color values themselves are not saturated. The color value (R, G or B) is saturated if it is equal to the maximum value of 65535. In that case you have to reduce the gain, seesetConfig(short, short)
.- Throws:
TinkerforgeException
-
setIlluminanceCallbackPeriod
public void setIlluminanceCallbackPeriod(long period) throws TinkerforgeException
Sets the period with which theBrickletColor.IlluminanceListener
listener is triggered periodically. A value of 0 turns the listener off. TheBrickletColor.IlluminanceListener
listener is only triggered if the illuminance has changed since the last triggering.- Throws:
TinkerforgeException
-
getIlluminanceCallbackPeriod
public long getIlluminanceCallbackPeriod() throws TinkerforgeException
Returns the period as set bysetIlluminanceCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
setColorTemperatureCallbackPeriod
public void setColorTemperatureCallbackPeriod(long period) throws TinkerforgeException
Sets the period with which theBrickletColor.ColorTemperatureListener
listener is triggered periodically. A value of 0 turns the listener off. TheBrickletColor.ColorTemperatureListener
listener is only triggered if the color temperature has changed since the last triggering.- Throws:
TinkerforgeException
-
getColorTemperatureCallbackPeriod
public long getColorTemperatureCallbackPeriod() throws TinkerforgeException
Returns the period as set bysetColorTemperatureCallbackPeriod(long)
.- Throws:
TinkerforgeException
-
getIdentity
public Device.Identity getIdentity() throws TinkerforgeException
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier. The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at position 'z'. The device identifier numbers can be found :ref:`here <device_identifier>`. |device_identifier_constant|- Specified by:
getIdentity
in classDevice
- Throws:
TinkerforgeException
-
addColorListener
public void addColorListener(BrickletColor.ColorListener listener)
Adds a Color listener.
-
removeColorListener
public void removeColorListener(BrickletColor.ColorListener listener)
Removes a Color listener.
-
addColorReachedListener
public void addColorReachedListener(BrickletColor.ColorReachedListener listener)
Adds a ColorReached listener.
-
removeColorReachedListener
public void removeColorReachedListener(BrickletColor.ColorReachedListener listener)
Removes a ColorReached listener.
-
addIlluminanceListener
public void addIlluminanceListener(BrickletColor.IlluminanceListener listener)
Adds a Illuminance listener.
-
removeIlluminanceListener
public void removeIlluminanceListener(BrickletColor.IlluminanceListener listener)
Removes a Illuminance listener.
-
addColorTemperatureListener
public void addColorTemperatureListener(BrickletColor.ColorTemperatureListener listener)
Adds a ColorTemperature listener.
-
removeColorTemperatureListener
public void removeColorTemperatureListener(BrickletColor.ColorTemperatureListener listener)
Removes a ColorTemperature listener.
-
-