Skip to main content

Meadow.Foundation.Sensors.Motion.Apds9960

Apds9960
StatusStatus badge: in-progress
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Motion.Apds9960

Code Example

Apds9960 sensor;

public MeadowApp()
{
Console.WriteLine("Initializing...");

// configure our sensor on the I2C Bus
var i2c = Device.CreateI2cBus();
sensor = new Apds9960(Device, i2c, Device.Pins.D00);

// classical .NET events can also be used:
sensor.Updated += (sender, result) => {
Console.WriteLine($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Console.WriteLine($" Color: {result.New.Color:N2}Lux");
};

//==== enable the features we want
sensor.EnableLightSensor(false);

//==== 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($" Ambient Light: {result.AmbientLight?.Lux:N2}Lux");
Console.WriteLine($" Color: {result.Color:N2}Lux");
}

Sample project(s) available on GitHub