Skip to main content

Meadow.Foundation.Sensors.Color.Tcs3472x

Tcs3472x
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Color.Tcs3472x

Code Example​

private Tcs3472x sensor;

public override Task Initialize()
{
Resolver.Log.Info("Initialize...");

// configure our sensor on the I2C Bus
sensor = new Tcs3472x(Device.CreateI2cBus());

// Example that uses an IObservable subscription to only be notified when the filter is satisfied
var consumer = Tcs3472x.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisfied: {result.New}, old: {result.Old}"),
filter: result =>
{
if (result.Old is { } old)
{
return Math.Abs(result.New.R - old.R) > 50;
}
return false;
});
sensor.Subscribe(consumer);

// classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Color: {result.New}");
};

return Task.CompletedTask;
}

public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info($"Initial reading: {result}");

sensor.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub

API Reference​

Class Tcs3472x

Represents a Tcs3472x color sensor.

Assembly: Tcs3472x.dll​
View Source​
Declaration
public class Tcs3472x : ByteCommsSensorBase<Color>, IObservable<IChangeResult<Color>>, IDisposable, IColorSensor, ISamplingSensor<Color>, ISensor<Color>, ISensor, ISamplingSensor, II2cPeripheral

Inheritance: System.Object -> Meadow.Foundation.ObservableBase<UNIT> -> Meadow.Foundation.SamplingSensorBase<UNIT> -> Meadow.Foundation.PollingSensorBase<UNIT> -> Meadow.Foundation.ByteCommsSensorBase<UNIT>

Implements:
System.IObservable<Meadow.IChangeResult<Meadow.Color>>, System.IDisposable, Meadow.Peripherals.Sensors.Color.IColorSensor, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Color>, Meadow.Peripherals.Sensors.ISensor<Meadow.Color>, Meadow.Peripherals.Sensors.ISensor, Meadow.Peripherals.Sensors.ISamplingSensor, Meadow.Hardware.II2cPeripheral

Properties​

DefaultI2cAddress​

Default I2C address for the TCS3472x family.

View Source​
Declaration
public byte DefaultI2cAddress { get; }

IntegrationTime​

Gets or sets the integration time for the sensor.

View Source​
Declaration
public double IntegrationTime { get; set; }

CurrentGain​

Gets or sets the gain.

View Source​
Declaration
public Tcs3472x.Gain CurrentGain { get; set; }

Color​

Gets the last color read from the sensor.

View Source​
Declaration
public Color? Color { get; }

Methods​

SetInterrupt(bool)​

Sets or clears the colors and clear interrupts.

View Source​
Declaration
public void SetInterrupt(bool state)
Parameters​
TypeNameDescription
System.BooleanstateTrue to set all interrupts, false to clear.

SetInterrupt(InterruptState, bool)​

Sets or clears a specific interrupt persistence.

View Source​
Declaration
public void SetInterrupt(Tcs3472x.InterruptState interrupt, bool state)
Parameters​
TypeNameDescription
Meadow.Foundation.Sensors.Color.Tcs3472x.InterruptStateinterruptThe persistence cycles.
System.BooleanstateTrue to set the interrupt, false to clear.

GetColor(bool)​

Gets the current color reading from the sensor.

View Source​
Declaration
public Task<Color> GetColor(bool delay = true)
Returns​

System.Threading.Tasks.Task<Meadow.Color>: The current color reading.

Parameters​
TypeNameDescription
System.BooleandelayWait to read the data that the integration time has passed.

ReadSensor()​

Read value from sensor

View Source​
Declaration
protected override Task<Color> ReadSensor()
Returns​

System.Threading.Tasks.Task<Meadow.Color>: unitized value

Implements​

  • System.IObservable<Meadow.IChangeResult<Meadow.Color>>
  • System.IDisposable
  • Meadow.Peripherals.Sensors.Color.IColorSensor
  • Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Color>
  • Meadow.Peripherals.Sensors.ISensor<Meadow.Color>
  • Meadow.Peripherals.Sensors.ISensor
  • Meadow.Peripherals.Sensors.ISamplingSensor
  • Meadow.Hardware.II2cPeripheral