public class TCS3200 extends Object implements InputEventListener<DigitalInputEvent>, Runnable, Closeable
This class reads RGB values from a TCS3200 colour sensor. Connections:
GND Ground. VDD Supply Voltage (2.7-5.5V) /OE Output enable, active low. When OE is high OUT is disabled allowing multiple sensors to share the same OUT line. OUT Output frequency square wave. S0/S1 Output frequency scale selection. S2/S3 Colour filter selection.
To take a reading the colour filters are selected in turn for a fraction of a second and the frequency is read and converted to Hz.
Modifier and Type | Class and Description |
---|---|
static class |
TCS3200.Filter |
static class |
TCS3200.Frequency |
Modifier and Type | Field and Description |
---|---|
static int |
NOT_SET |
Constructor and Description |
---|
TCS3200(int outGpio,
int s2Gpio,
int s3Gpio) |
TCS3200(int outGpio,
int s2Gpio,
int s3Gpio,
int s0Gpio,
int s1Gpio,
int oeGpio) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
int[] |
getBlackLevel()
Get the black level calibration
|
TCS3200.Frequency |
getFrequency()
Get the current frequency scaling
|
int[] |
getHertz()
Get the latest hertz reading
|
int[] |
getRgb()
Get the latest RGB reading.
|
int |
getSampleSize()
Get the sample size
|
double |
getUpdateInterval()
Get the interval between RGB updates
|
int[] |
getWhiteLevel()
Get the white level calibration
|
void |
pause()
Pause reading (until a call to resume).
|
void |
resume()
Resume reading (after a call to pause)
|
void |
run() |
void |
setBlackLevel(int[] rgb)
Set the black level calibration
|
void |
setFilter(TCS3200.Filter f)
Set the colour to be sampled.
|
void |
setFrequency(TCS3200.Frequency f)
Set the frequency scaling.
|
void |
setSampleSize(int samples)
Set the sample size (number of frequency cycles to accumulate)
|
void |
setUpdateInterval(double interval)
Set the interval between RGB updates
|
void |
setWhiteLevel(int[] rgb)
Set the white level calibration
|
void |
valueChanged(DigitalInputEvent event) |
public static final int NOT_SET
public TCS3200(int outGpio, int s2Gpio, int s3Gpio)
public TCS3200(int outGpio, int s2Gpio, int s3Gpio, int s0Gpio, int s1Gpio, int oeGpio)
public int[] getRgb()
public int[] getHertz()
public int[] getBlackLevel()
public void setBlackLevel(int[] rgb)
rgb
- new black levelspublic int[] getWhiteLevel()
public void setWhiteLevel(int[] rgb)
rgb
- new white levelspublic TCS3200.Frequency getFrequency()
public void setFrequency(TCS3200.Frequency f)
f S0 S1 Frequency scaling 0 L L Off 1 L H 2% 2 H L 20% 3 H H 100%
f
- Sampling frequencypublic double getUpdateInterval()
public void setUpdateInterval(double interval)
interval
- the interval between RGB updates ( 0.1 <= interval < 2.0)public int getSampleSize()
public void setSampleSize(int samples)
samples
- the sample sizepublic void pause()
public void resume()
public void setFilter(TCS3200.Filter f)
f
- Filterpublic void valueChanged(DigitalInputEvent event)
valueChanged
in interface InputEventListener<DigitalInputEvent>
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2016–2017 mattjlewis. All rights reserved.