Remarks
Apds9960 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
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
Syntax
public class Apds9960 : ByteCommsSensorBase<(Color? Color, Illuminance? AmbientLight)>, ISamplingSensor<(Color? Color, Illuminance? AmbientLight)>, ISamplingSensor<(Color? Color, Illuminance? AmbientLight)>, IDisposable
Constructors
Apds9960(II2cBus, IPin)
Create a new instance of the APDS9960 communicating over the I2C interface.
Declaration
public Apds9960(II2cBus i2cBus, IPin interruptPin)
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | SI2C bus object |
IPin | interruptPin | The interrupt pin |
Properties
AmbientLight
The current abient light value
Declaration
public Illuminance? AmbientLight { get; }
Property Value
Type | Description |
---|---|
System.Nullable<Illuminance> |
Color
The current color value
Declaration
public Color? Color { get; }
Property Value
Type | Description |
---|---|
System.Nullable<Color> |
Methods
DisableGestureSensor()
Disable gestures
Declaration
public void DisableGestureSensor()
DisableLightSensor()
Disable light sensor
Declaration
public void DisableLightSensor()
DisableProximitySensor()
Disable proximity sensor
Declaration
public void DisableProximitySensor()
EnableGestureSensor(Boolean)
Starts the gesture recognition engine on the APDS-9960
Declaration
public bool EnableGestureSensor(bool interrupts)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | interrupts |
Returns
Type | Description |
---|---|
System.Boolean | Enable interrupts for gestures |
EnableLightSensor(Boolean)
Enable light sensor
Declaration
public void EnableLightSensor(bool interrupts)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | interrupts | True to enable interrupts for light |
EnablePower(Boolean)
Enable power
Declaration
public void EnablePower(bool enable)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | enable | True to enable, false to disable |
EnableProximitySensor(Boolean)
Enable proximity sensor
Declaration
public void EnableProximitySensor(bool interrupts)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | interrupts | True to enable interrupts for proximity |
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()
Is a gesture reading available
Declaration
public bool IsGestureAvailable()
Returns
Type | Description |
---|---|
System.Boolean | True if available |
RaiseEventsAndNotify(IChangeResult<(Nullable<Color> Color, Nullable<Illuminance> AmbientLight)>)
Raise events for subcribers and notify of value changes
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 | The updated sensor data |
ReadAmbientLight()
Read ambient light value
Declaration
protected ushort ReadAmbientLight()
Returns
Type | Description |
---|---|
System.UInt16 |
ReadBlueLight()
Read blue light value
Declaration
protected ushort ReadBlueLight()
Returns
Type | Description |
---|---|
System.UInt16 |
ReadGesture()
Read the current gesure
Declaration
public Apds9960.Direction ReadGesture()
Returns
Type | Description |
---|---|
Apds9960.Direction | The direction |
ReadGreenLight()
Read green light value
Declaration
protected ushort ReadGreenLight()
Returns
Type | Description |
---|---|
System.UInt16 |
ReadProximity()
Read proximity
Declaration
public byte ReadProximity()
Returns
Type | Description |
---|---|
System.Byte |
ReadRedLight()
Read red light value
Declaration
protected ushort ReadRedLight()
Returns
Type | Description |
---|---|
System.UInt16 |
ReadSensor()
Reads data from the sensor
Declaration
protected override Task<(Color? Color, Illuminance? AmbientLight)> ReadSensor()
Returns
Type | Description |
---|---|
Task<System.ValueTuple<System.Nullable<Color>, System.Nullable<Illuminance>>> | The latest sensor reading |
Overrides
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
Raised when the ambient light value changes
Declaration
public event EventHandler<IChangeResult<Illuminance>> AmbientLightUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<Illuminance>> |
ColorUpdated
Raised when the color value changes
Declaration
public event EventHandler<IChangeResult<Color>> ColorUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<Color>> |