Remarks
Max44009 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The Max44009 is an analog ambient light sensor.
Code Example
Max44009 sensor;
public MeadowApp()
{
Console.WriteLine("Initializing...");
sensor = new Max44009(Device.CreateI2cBus());
// Example that uses an IObservable subscription to only be notified when the filter is satisfied
var consumer = Max44009.CreateObserver(
handler: result => Console.WriteLine($"Observer: filter satisifed: {result.New.Lux:N2}Lux, old: {result.Old?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result => {
if (result.Old is { } old) { //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New - old).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
// classical .NET events can also be used:
sensor.Updated += (sender, result) => {
Console.WriteLine($"Light: {result.New.Lux:N2}Lux");
};
//==== one-off read
ReadConditions().Wait();
// start updating continuously
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
protected async Task ReadConditions()
{
var result = await sensor.Read();
Console.WriteLine("Initial Readings:");
Console.WriteLine($" Light: {result.Lux:N2}Lux");
}
Sample project(s) available on GitHub
Wiring Example
To wire a Max44009 to your Meadow board, connect the following:
Max44009 | Meadow Pin |
---|---|
SCL | D08 |
SDA | D07 |
GND | GND |
VCC | 3V3 |
It should look like the following diagram:
Syntax
public class Max44009 : ByteCommsSensorBase<Illuminance>, IDisposable
Constructors
Max44009(II2cBus, Byte)
Declaration
public Max44009(II2cBus i2cBus, byte address = null)
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | |
System.Byte | address |
Methods
Initialize()
Declaration
protected void Initialize()
ReadSensor()
Declaration
protected override Task<Illuminance> ReadSensor()
Returns
Type | Description |
---|---|
Task<Illuminance> |
Overrides
Meadow.Foundation.SensorBase<Illuminance>.ReadSensor()