Remarks
Temt6000 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The TEMT6000 is an analog ambient light sensor.
Code Example
Temt6000 sensor;
public MeadowApp()
{
Console.WriteLine("Initializing...");
// configure our sensor
sensor = new Temt6000(Device, Device.Pins.A03);
// Example that uses an IObservable subscription to only be notified when the voltage changes by at least 0.5V
var consumer = Temt6000.CreateObserver(
handler: result => Console.WriteLine($"Observer filter satisfied: {result.New.Volts:N2}V, old: {result.Old?.Volts:N2}V"),
// only notify if the change is greater than 0.5V
filter: result => {
if (result.Old is { } old) { //c# 8 pattern match syntax. checks for !null and assigns var.
return (result.New - old).Abs().Volts > 0.5; // returns true if > 0.5V change.
}
return false;
});
sensor.Subscribe(consumer);
// classical .NET events can also be used:
sensor.Updated += (sender, result) => {
Console.WriteLine($"Voltage Changed, new: {result.New.Volts:N2}V, old: {result.Old?.Volts:N2}V");
};
//==== One-off reading use case/pattern
ReadTemp().Wait();
sensor.StartUpdating(TimeSpan.FromMilliseconds(1000));
}
protected async Task ReadTemp()
{
var result = await sensor.Read();
Console.WriteLine($"Initial temp: {result.Volts:N2}V");
}
Sample project(s) available on GitHub
Wiring Example
To wire a Temt6000 to your Meadow board, connect the following:
Temt6000 | Meadow Pin |
---|---|
GND | GND |
SIG | A03 |
VCC | 3V3 |
It should look like the following diagram:
Characteristic | Locus |
---|---|
Inheritance | System.Object ObservableBase<Voltage> SensorBase<Voltage> AnalogObservableBase > Temt6000 |
Inherited Members | AnalogObservableBase.Voltage AnalogObservableBase.StartUpdating(Nullable<TimeSpan>) AnalogObservableBase.StopUpdating() AnalogObservableBase.ReadSensor() SensorBase<Voltage>.Updated SensorBase<Voltage>.samplingLock SensorBase<Voltage>.SamplingTokenSource SensorBase<Voltage>.Conditions SensorBase<Voltage>.IsSampling SensorBase<Voltage>.UpdateInterval SensorBase<Voltage>.RaiseEventsAndNotify(IChangeResult<Voltage>) SensorBase<Voltage>.Read() ObservableBase<Voltage>.observers ObservableBase<Voltage>.NotifyObservers(IChangeResult<Voltage>) Meadow.Foundation.ObservableBase<Meadow.Units.Voltage>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<Meadow.Units.Voltage>.CreateObserver(Action<>, System.Nullable<Predicate<Meadow.IChangeResult<UNIT>>>) |
Namespace | Meadow.Foundation.Sensors.Light |
Assembly | Temt6000.dll |
Syntax
public class Temt6000 : AnalogObservableBase
Constructors
Temt6000(IAnalogInputController, IPin, Int32, Nullable<TimeSpan>, Nullable<Voltage>)
Creates a new Temt6000 driver
Declaration
public Temt6000(IAnalogInputController device, IPin pin, int sampleCount = 5, TimeSpan? sampleInterval = null, Voltage? voltage = null)
Parameters
Type | Name | Description |
---|---|---|
IAnalogInputController | device | |
IPin | pin | AnalogChannel connected to the sensor. |
System.Int32 | sampleCount | |
System.Nullable<TimeSpan> | sampleInterval | |
System.Nullable<Voltage> | voltage |
Temt6000(IAnalogInputPort)
Creates a new Temt6000 driver
Declaration
public Temt6000(IAnalogInputPort port)
Parameters
Type | Name | Description |
---|---|---|
IAnalogInputPort | port |