Remarks

Apds9960
Status Status badge: in-progress
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet 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

Characteristic Locus
Inheritance System.Object ObservableBase<System.ValueTuple<System.Nullable<Color>, System.Nullable<Illuminance>>> SensorBase<System.ValueTuple<System.Nullable<Color>, System.Nullable<Illuminance>>> SamplingSensorBase<System.ValueTuple<System.Nullable<Color>, System.Nullable<Illuminance>>> ByteCommsSensorBase<System.ValueTuple<System.Nullable<Color>, System.Nullable<Illuminance>>> > Apds9960
Implements IDisposable
Inherited Members ByteCommsSensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.Peripheral ByteCommsSensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.ReadBuffer ByteCommsSensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.WriteBuffer ByteCommsSensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.Init(Int32, Int32) ByteCommsSensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.Dispose(Boolean) ByteCommsSensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.Dispose() SamplingSensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.StartUpdating(Nullable<TimeSpan>) SamplingSensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.StopUpdating() SensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.Updated SensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.samplingLock SensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.SamplingTokenSource SensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.Conditions SensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.IsSampling SensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.UpdateInterval SensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.ReadSensor() SensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.RaiseEventsAndNotify(IChangeResult<>) SensorBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.Read() ObservableBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.observers ObservableBase<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Meadow.Foundation.Color>, System.Nullable<Illuminance>>>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Meadow.Foundation.Color>, System.Nullable<Illuminance>>>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Motion
Assembly Apds9960.dll

Syntax

public class Apds9960 : ByteCommsSensorBase<(Color? Color, Illuminance? AmbientLight)>, IDisposable

Constructors

Apds9960(IMeadowDevice, II2cBus, IPin)

Create a new instance of the APDS9960 communicating over the I2C interface.

Declaration
public Apds9960(IMeadowDevice device, II2cBus i2cBus, IPin interruptPin)

Parameters

Type Name Description
IMeadowDevice device
II2cBus i2cBus

SI2C bus object

IPin interruptPin

Properties

AmbientLight

Declaration
public Illuminance? AmbientLight { get; }

Property Value

Type Description
System.Nullable<Illuminance>

Color

Declaration
public Color? Color { get; }

Property Value

Type Description
System.Nullable<Color>

Methods

DisableGestureSensor()

Declaration
public void DisableGestureSensor()

DisableLightSensor()

Declaration
public void DisableLightSensor()

DisableProximitySensor()

Declaration
public void DisableProximitySensor()

EnableGestureSensor(Boolean)

Declaration
public bool EnableGestureSensor(bool interrupts)

Parameters

Type Name Description
System.Boolean interrupts

Returns

Type Description
System.Boolean

EnableLightSensor(Boolean)

Declaration
public void EnableLightSensor(bool interrupts)

Parameters

Type Name Description
System.Boolean interrupts

EnablePower(Boolean)

Declaration
public void EnablePower(bool enable)

Parameters

Type Name Description
System.Boolean enable

EnableProximitySensor(Boolean)

Declaration
public void EnableProximitySensor(bool interrupts)

Parameters

Type Name Description
System.Boolean interrupts

GetLEDDrive()

Declaration
public byte GetLEDDrive()

Returns

Type Description
System.Byte

GetProximityGain()

Declaration
public byte GetProximityGain()

Returns

Type Description
System.Byte

GetProxIntHighThresh()

Declaration
public byte GetProxIntHighThresh()

Returns

Type Description
System.Byte

GetProxIntLowThresh()

Declaration
public byte GetProxIntLowThresh()

Returns

Type Description
System.Byte

IsGestureAvailable()

Declaration
public bool IsGestureAvailable()

Returns

Type Description
System.Boolean

RaiseEventsAndNotify(IChangeResult<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>)

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(Color? Color, Illuminance? AmbientLight)> changeResult)

Parameters

Type Name Description
IChangeResult<System.ValueTuple<System.Nullable<Color>, System.Nullable<Illuminance>>> changeResult

ReadAmbientLight()

Declaration
protected ushort ReadAmbientLight()

Returns

Type Description
System.UInt16

ReadBlueLight()

Declaration
protected ushort ReadBlueLight()

Returns

Type Description
System.UInt16

ReadGesture()

Declaration
public Apds9960.Direction ReadGesture()

Returns

Type Description
Apds9960.Direction

ReadGreenLight()

Declaration
protected ushort ReadGreenLight()

Returns

Type Description
System.UInt16

ReadProximity()

Declaration
public byte ReadProximity()

Returns

Type Description
System.Byte

ReadRedLight()

Declaration
protected ushort ReadRedLight()

Returns

Type Description
System.UInt16

ReadSensor()

Declaration
protected override Task<(Color? Color, Illuminance? AmbientLight)> ReadSensor()

Returns

Type Description
Task<System.ValueTuple<System.Nullable<Color>, System.Nullable<Illuminance>>>

Overrides

Meadow.Foundation.SensorBase<System.ValueTuple<System.Nullable<Meadow.Foundation.Color>, System.Nullable<Illuminance>>>.ReadSensor()

SetLEDDrive(Byte)

Declaration
public bool SetLEDDrive(byte drive)

Parameters

Type Name Description
System.Byte drive

Returns

Type Description
System.Boolean

SetProximityGain(Byte)

Declaration
public void SetProximityGain(byte drive)

Parameters

Type Name Description
System.Byte drive

SetProxIntHighThresh(Byte)

Declaration
public void SetProxIntHighThresh(byte threshold)

Parameters

Type Name Description
System.Byte threshold

SetProxIntLowThresh(Byte)

Declaration
public void SetProxIntLowThresh(byte threshold)

Parameters

Type Name Description
System.Byte threshold

Events

AmbientLightUpdated

Declaration
public event EventHandler<IChangeResult<Illuminance>> AmbientLightUpdated

Event Type

Type Description
EventHandler<IChangeResult<Illuminance>>

ColorUpdated

Declaration
public event EventHandler<IChangeResult<Color>> ColorUpdated

Event Type

Type Description
EventHandler<IChangeResult<Color>>