Class TCS3200

java.lang.Object
com.diozero.devices.sandpit.TCS3200
All Implemented Interfaces:
DeviceInterface, DeviceEventConsumer<DigitalInputEvent>, AutoCloseable, Runnable, Consumer<DigitalInputEvent>

public class TCS3200
extends Object
implements DeviceEventConsumer<DigitalInputEvent>, Runnable, DeviceInterface

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.
 
  • OUT is a square wave whose frequency is proportional to the intensity of the selected filter colour.
  • S2/S3 selects between red, green, blue, and no filter.
  • S0/S1 scales the frequency at 100%, 20%, 2% or off.

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.

  • Field Details

  • Constructor Details

    • TCS3200

      public TCS3200​(int outGpio, int s2Gpio, int s3Gpio)
    • TCS3200

      public TCS3200​(int outGpio, int s2Gpio, int s3Gpio, int s0Gpio, int s1Gpio, int oeGpio)
  • Method Details

    • getRgb

      public int[] getRgb()
      Get the latest RGB reading. The raw colour hertz readings are converted to RGB values as follows: RGB = 255 * (Fv - Fb) / (Fw - Fb) Where Fv is the sampled hertz, Fw is the calibrated white hertz, and Fb is the calibrated black hertz.
      Returns:
      RGB values constrained to be between 0 and 255
    • getHertz

      public int[] getHertz()
      Get the latest hertz reading
      Returns:
      latest hertz reading
    • getBlackLevel

      public int[] getBlackLevel()
      Get the black level calibration
      Returns:
      black level calibration
    • setBlackLevel

      public void setBlackLevel​(int[] rgb)
      Set the black level calibration
      Parameters:
      rgb - new black levels
    • getWhiteLevel

      public int[] getWhiteLevel()
      Get the white level calibration
      Returns:
      white level calibration
    • setWhiteLevel

      public void setWhiteLevel​(int[] rgb)
      Set the white level calibration
      Parameters:
      rgb - new white levels
    • getFrequency

      public TCS3200.Frequency getFrequency()
      Get the current frequency scaling
      Returns:
      the current frequency scaling
    • setFrequency

      public void setFrequency​(TCS3200.Frequency f)
      Set the frequency scaling.
       f  S0  S1  Frequency scaling
       0  L   L   Off
       1  L   H   2%
       2  H   L   20%
       3  H   H   100%
       
      Parameters:
      f - Sampling frequency
    • getUpdateInterval

      public double getUpdateInterval()
      Get the interval between RGB updates
      Returns:
      the interval between RGB updates
    • setUpdateInterval

      public void setUpdateInterval​(double interval)
      Set the interval between RGB updates
      Parameters:
      interval - the interval between RGB updates ( 0.1 <= interval < 2.0)
    • getSampleSize

      public int getSampleSize()
      Get the sample size
      Returns:
      the sample size
    • setSampleSize

      public void setSampleSize​(int samples)
      Set the sample size (number of frequency cycles to accumulate)
      Parameters:
      samples - the sample size
    • pause

      public void pause()
      Pause reading (until a call to resume).
    • resume

      public void resume()
      Resume reading (after a call to pause)
    • setFilter

      public void setFilter​(TCS3200.Filter f)
      Set the colour to be sampled. f S2 S3 Photodiode 0 L L Red 1 H H Green 2 L H Blue 3 H L Clear (no filter)
      Parameters:
      f - Filter
    • accept

      public void accept​(DigitalInputEvent event)
      Specified by:
      accept in interface Consumer<DigitalInputEvent>
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • close

      public void close()
      Description copied from interface: DeviceInterface
      Close this device
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface DeviceInterface