Meadow.Foundation.Sensors.Color.Tcs3472x
| Tcs3472x | |
|---|---|
| Status | |
| Source code | GitHub |
| Datasheet(s) | GitHub |
| NuGet package |
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
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
public byte DefaultI2cAddress { get; }
IntegrationTime
Gets or sets the integration time for the sensor.
View Source
public double IntegrationTime { get; set; }
CurrentGain
Gets or sets the gain.
View Source
public Tcs3472x.Gain CurrentGain { get; set; }
Color
Gets the last color read from the sensor.
View Source
public Color? Color { get; }
Methods
SetInterrupt(bool)
Sets or clears the colors and clear interrupts.
View Source
public void SetInterrupt(bool state)
Parameters
| Type | Name | Description |
|---|---|---|
System.Boolean | state | True to set all interrupts, false to clear. |
SetInterrupt(InterruptState, bool)
Sets or clears a specific interrupt persistence.
View Source
public void SetInterrupt(Tcs3472x.InterruptState interrupt, bool state)
Parameters
| Type | Name | Description |
|---|---|---|
| Meadow.Foundation.Sensors.Color.Tcs3472x.InterruptState | interrupt | The persistence cycles. |
System.Boolean | state | True to set the interrupt, false to clear. |
GetColor(bool)
Gets the current color reading from the sensor.
View Source
public Task<Color> GetColor(bool delay = true)
Returns
System.Threading.Tasks.Task<Meadow.Color>: The current color reading.
Parameters
| Type | Name | Description |
|---|---|---|
System.Boolean | delay | Wait to read the data that the integration time has passed. |
ReadSensor()
Read value from sensor
View Source
protected override Task<Color> ReadSensor()
Returns
System.Threading.Tasks.Task<Meadow.Color>: unitized value
Implements
System.IObservable<Meadow.IChangeResult<Meadow.Color>>System.IDisposableMeadow.Peripherals.Sensors.Color.IColorSensorMeadow.Peripherals.Sensors.ISamplingSensor<Meadow.Color>Meadow.Peripherals.Sensors.ISensor<Meadow.Color>Meadow.Peripherals.Sensors.ISensorMeadow.Peripherals.Sensors.ISamplingSensorMeadow.Hardware.II2cPeripheral