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

Class Apds9960

Represents the APDS9960 Proximity, Light, RGB, and Gesture Sensor

Assembly: Apds9960.dll
View Source
Declaration
public class Apds9960 : ByteCommsSensorBase<(Color? Color, Illuminance? AmbientLight)>, IObservable<IChangeResult<(Color? Color, Illuminance? AmbientLight)>>, ISamplingSensor<(Color? Color, Illuminance? AmbientLight)>, ISensor<(Color? Color, Illuminance? AmbientLight)>, ISensor, ISamplingSensor, II2cPeripheral, IDisposable

Inheritance: System.Object -> Meadow.Foundation.ObservableBase<UNIT>

Implements:
System.IObservable<Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Color>,System.Nullable<Meadow.Units.Illuminance>>>>, Meadow.Peripherals.Sensors.ISamplingSensor<System.ValueTuple<System.Nullable<Meadow.Color>,System.Nullable<Meadow.Units.Illuminance>>>, Meadow.Peripherals.Sensors.ISensor<System.ValueTuple<System.Nullable<Meadow.Color>,System.Nullable<Meadow.Units.Illuminance>>>, Meadow.Peripherals.Sensors.ISensor, Meadow.Peripherals.Sensors.ISamplingSensor, Meadow.Hardware.II2cPeripheral, System.IDisposable

Properties

DefaultI2cAddress

The default I2C address for the peripheral

View Source
Declaration
public byte DefaultI2cAddress { get; }

IsDisposed

Is the object disposed

View Source
Declaration
public bool IsDisposed { get; }

Color

The current color value

View Source
Declaration
public Color? Color { get; }

AmbientLight

The current ambient light value

View Source
Declaration
public Illuminance? AmbientLight { get; }

Methods

ReadSensor()

Reads data from the sensor

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

System.Threading.Tasks.Task<System.ValueTuple<System.Nullable<Meadow.Color>,System.Nullable<Meadow.Units.Illuminance>>>: The latest sensor reading### RaiseEventsAndNotify(IChangeResult<(Color? Color, Illuminance? AmbientLight)>) Raise events for subscribers and notify of value changes

View Source
Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(Color? Color, Illuminance? AmbientLight)> changeResult)
Parameters
TypeNameDescription
Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Color>,System.Nullable<Meadow.Units.Illuminance>>>changeResultThe updated sensor data

EnableLightSensor(bool)

Enable light sensor

View Source
Declaration
public void EnableLightSensor(bool interrupts)
Parameters
TypeNameDescription
System.BooleaninterruptsTrue to enable interrupts for light

DisableLightSensor()

Disable light sensor

View Source
Declaration
public void DisableLightSensor()

EnableProximitySensor(bool)

Enable proximity sensor

View Source
Declaration
public void EnableProximitySensor(bool interrupts)
Parameters
TypeNameDescription
System.BooleaninterruptsTrue to enable interrupts for proximity

DisableProximitySensor()

Disable proximity sensor

View Source
Declaration
public void DisableProximitySensor()

EnableGestureSensor(bool)

Starts the gesture recognition engine on the APDS-9960

View Source
Declaration
public bool EnableGestureSensor(bool interrupts)
Returns

System.Boolean: Enable interrupts for gestures

Parameters
TypeName
System.Booleaninterrupts

DisableGestureSensor()

Disable gestures

View Source
Declaration
public void DisableGestureSensor()

IsGestureAvailable()

Is a gesture reading available

View Source
Declaration
public bool IsGestureAvailable()
Returns

System.Boolean: True if available### ReadGesture() Read the current gesture

View Source
Declaration
public Apds9960.Direction ReadGesture()
Returns

Meadow.Foundation.Sensors.Motion.Apds9960.Direction: The direction

Exceptions

System.Exception
Throws if reading gesture data failed

EnablePower(bool)

Enable power

View Source
Declaration
public void EnablePower(bool enable)
Parameters
TypeNameDescription
System.BooleanenableTrue to enable, false to disable

ReadAmbientLight()

Read ambient light value

View Source
Declaration
protected ushort ReadAmbientLight()
Returns

System.UInt16

ReadRedLight()

Read red light value

View Source
Declaration
protected ushort ReadRedLight()
Returns

System.UInt16

ReadGreenLight()

Read green light value

View Source
Declaration
protected ushort ReadGreenLight()
Returns

System.UInt16

ReadBlueLight()

Read blue light value

View Source
Declaration
protected ushort ReadBlueLight()
Returns

System.UInt16

ReadProximity()

Read proximity

View Source
Declaration
public byte ReadProximity()
Returns

System.Byte

GetProxIntLowThresh()

View Source
Declaration
public byte GetProxIntLowThresh()
Returns

System.Byte

SetProxIntLowThresh(byte)

View Source
Declaration
public void SetProxIntLowThresh(byte threshold)
Parameters
TypeName
System.Bytethreshold

GetProxIntHighThresh()

View Source
Declaration
public byte GetProxIntHighThresh()
Returns

System.Byte

SetProxIntHighThresh(byte)

View Source
Declaration
public void SetProxIntHighThresh(byte threshold)
Parameters
TypeName
System.Bytethreshold

GetLEDDrive()

View Source
Declaration
public byte GetLEDDrive()
Returns

System.Byte

SetLEDDrive(byte)

View Source
Declaration
public bool SetLEDDrive(byte drive)
Returns

System.Boolean

Parameters
TypeName
System.Bytedrive

GetProximityGain()

View Source
Declaration
public byte GetProximityGain()
Returns

System.Byte

SetProximityGain(byte)

View Source
Declaration
public void SetProximityGain(byte drive)
Parameters
TypeName
System.Bytedrive

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

View Source
Declaration
public override void Dispose()

Dispose(bool)

Dispose of the object

View Source
Declaration
protected override void Dispose(bool disposing)
Parameters
TypeNameDescription
System.BooleandisposingIs disposing

Events

AmbientLightUpdated

Raised when the ambient light value changes

View Source
Declaration
public event EventHandler<IChangeResult<Illuminance>> AmbientLightUpdated
Event Type

System.EventHandler<Meadow.IChangeResult<Meadow.Units.Illuminance>>

ColorUpdated

Raised when the color value changes

View Source
Declaration
public event EventHandler<IChangeResult<Color>> ColorUpdated
Event Type

System.EventHandler<Meadow.IChangeResult<Meadow.Color>>

Implements

  • System.IObservable<Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Color>,System.Nullable<Meadow.Units.Illuminance>>>>
  • Meadow.Peripherals.Sensors.ISamplingSensor<System.ValueTuple<System.Nullable<Meadow.Color>,System.Nullable<Meadow.Units.Illuminance>>>
  • Meadow.Peripherals.Sensors.ISensor<System.ValueTuple<System.Nullable<Meadow.Color>,System.Nullable<Meadow.Units.Illuminance>>>
  • Meadow.Peripherals.Sensors.ISensor
  • Meadow.Peripherals.Sensors.ISamplingSensor
  • Meadow.Hardware.II2cPeripheral
  • System.IDisposable