Remarks

AnalogLightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogLightSensor analogLightSensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    // configure our AnalogLightSensor sensor
    analogLightSensor = new AnalogLightSensor(
        analogPin: Device.Pins.A03);

    //==== IObservable Pattern with an optional notification filter.
    var consumer = AnalogLightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Lux:N2} lux, old: {result.Old.Value.Lux:N2} lux"),

        // only notify if the change is greater than 0.5
        filter: result => {
            if (result.Old is { } old) 
            {   //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Lux > 0.5; // returns true if > 0.5  change.
            }
            return false;
        }
        // if you want to always get notified, pass null for the filter:
        //filter: null
    );
    analogLightSensor.Subscribe(consumer);

    // classical .NET events can also be used:
    analogLightSensor.LuminosityUpdated += (sender, result) => 
        Resolver.Log.Info($"Lux changed: {result.New.Lux:N2} lux, old: {result.Old?.Lux:N2} lux");

    //==== One-off reading use case/pattern
    ReadIlluminance().Wait();

    // Spin up the sampling thread so that events are raised and IObservable notifications are sent.
    analogLightSensor.StartUpdating(TimeSpan.FromMilliseconds(1000));

    return Task.CompletedTask;
}

protected async Task ReadIlluminance()
{
    var illuminance = await analogLightSensor.Read();
    Resolver.Log.Info($"Initial lux: {illuminance.Lux:N2} lux");
}

Sample project(s) available on GitHub

Characteristic Locus
Inheritance object ObservableBase<Illuminance> SamplingSensorBase<Illuminance> > AnalogLightSensor
Implements IObservable<IChangeResult<Illuminance>> ILightSensor ISamplingSensor<Illuminance> ISensor<Illuminance>
Inherited Members SamplingSensorBase<Illuminance>.samplingLock SamplingSensorBase<Illuminance>.Updated SamplingSensorBase<Illuminance>.SamplingTokenSource SamplingSensorBase<Illuminance>.Conditions SamplingSensorBase<Illuminance>.IsSampling SamplingSensorBase<Illuminance>.UpdateInterval SamplingSensorBase<Illuminance>.Read() ObservableBase<Illuminance>.observers ObservableBase<Illuminance>.NotifyObservers(IChangeResult<Illuminance>) ObservableBase<Illuminance>.Subscribe(IObserver<IChangeResult<Illuminance>>) ObservableBase<Illuminance>.CreateObserver(Action<IChangeResult<Illuminance>>, Predicate<IChangeResult<Illuminance>>) object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString()
Namespace Meadow.Foundation.Sensors.Light
Assembly Meadow.Foundation.dll

Syntax

public class AnalogLightSensor : SamplingSensorBase<Illuminance>, IObservable<IChangeResult<Illuminance>>, ILightSensor, ISamplingSensor<Illuminance>, ISensor<Illuminance>

Constructors

AnalogLightSensor(IAnalogInputPort, Calibration?)

New instance of the AnalogLightSensor class.

Declaration
public AnalogLightSensor(IAnalogInputPort analogInputPort, AnalogLightSensor.Calibration? calibration = null)

Parameters

Type Name Description
IAnalogInputPort analogInputPort

Analog port the sensor is connected to.

AnalogLightSensor.Calibration calibration

Calibration for the analog sensor.

Remarks

AnalogLightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogLightSensor analogLightSensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    // configure our AnalogLightSensor sensor
    analogLightSensor = new AnalogLightSensor(
        analogPin: Device.Pins.A03);

    //==== IObservable Pattern with an optional notification filter.
    var consumer = AnalogLightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Lux:N2} lux, old: {result.Old.Value.Lux:N2} lux"),

        // only notify if the change is greater than 0.5
        filter: result => {
            if (result.Old is { } old) 
            {   //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Lux > 0.5; // returns true if > 0.5  change.
            }
            return false;
        }
        // if you want to always get notified, pass null for the filter:
        //filter: null
    );
    analogLightSensor.Subscribe(consumer);

    // classical .NET events can also be used:
    analogLightSensor.LuminosityUpdated += (sender, result) => 
        Resolver.Log.Info($"Lux changed: {result.New.Lux:N2} lux, old: {result.Old?.Lux:N2} lux");

    //==== One-off reading use case/pattern
    ReadIlluminance().Wait();

    // Spin up the sampling thread so that events are raised and IObservable notifications are sent.
    analogLightSensor.StartUpdating(TimeSpan.FromMilliseconds(1000));

    return Task.CompletedTask;
}

protected async Task ReadIlluminance()
{
    var illuminance = await analogLightSensor.Read();
    Resolver.Log.Info($"Initial lux: {illuminance.Lux:N2} lux");
}

Sample project(s) available on GitHub

AnalogLightSensor(IPin, Calibration?, int, TimeSpan?)

New instance of the AnalogLightSensor class.

Declaration
public AnalogLightSensor(IPin analogPin, AnalogLightSensor.Calibration? calibration = null, int sampleCount = 5, TimeSpan? sampleInterval = null)

Parameters

Type Name Description
IPin analogPin

Analog pin the sensor is connected to.

AnalogLightSensor.Calibration calibration

Calibration for the analog sensor.

int sampleCount

How many samples to take during a given reading. These are automatically averaged to reduce noise.

TimeSpan? sampleInterval

The time, in milliseconds, to wait in between samples during a reading.

Remarks

AnalogLightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogLightSensor analogLightSensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    // configure our AnalogLightSensor sensor
    analogLightSensor = new AnalogLightSensor(
        analogPin: Device.Pins.A03);

    //==== IObservable Pattern with an optional notification filter.
    var consumer = AnalogLightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Lux:N2} lux, old: {result.Old.Value.Lux:N2} lux"),

        // only notify if the change is greater than 0.5
        filter: result => {
            if (result.Old is { } old) 
            {   //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Lux > 0.5; // returns true if > 0.5  change.
            }
            return false;
        }
        // if you want to always get notified, pass null for the filter:
        //filter: null
    );
    analogLightSensor.Subscribe(consumer);

    // classical .NET events can also be used:
    analogLightSensor.LuminosityUpdated += (sender, result) => 
        Resolver.Log.Info($"Lux changed: {result.New.Lux:N2} lux, old: {result.Old?.Lux:N2} lux");

    //==== One-off reading use case/pattern
    ReadIlluminance().Wait();

    // Spin up the sampling thread so that events are raised and IObservable notifications are sent.
    analogLightSensor.StartUpdating(TimeSpan.FromMilliseconds(1000));

    return Task.CompletedTask;
}

protected async Task ReadIlluminance()
{
    var illuminance = await analogLightSensor.Read();
    Resolver.Log.Info($"Initial lux: {illuminance.Lux:N2} lux");
}

Sample project(s) available on GitHub

Properties

AnalogInputPort

Analog port connected to sensor

Declaration
protected IAnalogInputPort AnalogInputPort { get; }

Property Value

Type Description
IAnalogInputPort

Remarks

AnalogLightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogLightSensor analogLightSensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    // configure our AnalogLightSensor sensor
    analogLightSensor = new AnalogLightSensor(
        analogPin: Device.Pins.A03);

    //==== IObservable Pattern with an optional notification filter.
    var consumer = AnalogLightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Lux:N2} lux, old: {result.Old.Value.Lux:N2} lux"),

        // only notify if the change is greater than 0.5
        filter: result => {
            if (result.Old is { } old) 
            {   //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Lux > 0.5; // returns true if > 0.5  change.
            }
            return false;
        }
        // if you want to always get notified, pass null for the filter:
        //filter: null
    );
    analogLightSensor.Subscribe(consumer);

    // classical .NET events can also be used:
    analogLightSensor.LuminosityUpdated += (sender, result) => 
        Resolver.Log.Info($"Lux changed: {result.New.Lux:N2} lux, old: {result.Old?.Lux:N2} lux");

    //==== One-off reading use case/pattern
    ReadIlluminance().Wait();

    // Spin up the sampling thread so that events are raised and IObservable notifications are sent.
    analogLightSensor.StartUpdating(TimeSpan.FromMilliseconds(1000));

    return Task.CompletedTask;
}

protected async Task ReadIlluminance()
{
    var illuminance = await analogLightSensor.Read();
    Resolver.Log.Info($"Initial lux: {illuminance.Lux:N2} lux");
}

Sample project(s) available on GitHub

Illuminance

Current illuminance value read by sensor

Declaration
public Illuminance? Illuminance { get; }

Property Value

Type Description
Illuminance?

Remarks

AnalogLightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogLightSensor analogLightSensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    // configure our AnalogLightSensor sensor
    analogLightSensor = new AnalogLightSensor(
        analogPin: Device.Pins.A03);

    //==== IObservable Pattern with an optional notification filter.
    var consumer = AnalogLightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Lux:N2} lux, old: {result.Old.Value.Lux:N2} lux"),

        // only notify if the change is greater than 0.5
        filter: result => {
            if (result.Old is { } old) 
            {   //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Lux > 0.5; // returns true if > 0.5  change.
            }
            return false;
        }
        // if you want to always get notified, pass null for the filter:
        //filter: null
    );
    analogLightSensor.Subscribe(consumer);

    // classical .NET events can also be used:
    analogLightSensor.LuminosityUpdated += (sender, result) => 
        Resolver.Log.Info($"Lux changed: {result.New.Lux:N2} lux, old: {result.Old?.Lux:N2} lux");

    //==== One-off reading use case/pattern
    ReadIlluminance().Wait();

    // Spin up the sampling thread so that events are raised and IObservable notifications are sent.
    analogLightSensor.StartUpdating(TimeSpan.FromMilliseconds(1000));

    return Task.CompletedTask;
}

protected async Task ReadIlluminance()
{
    var illuminance = await analogLightSensor.Read();
    Resolver.Log.Info($"Initial lux: {illuminance.Lux:N2} lux");
}

Sample project(s) available on GitHub

LuminanceCalibration

Illuminance sensor callibration

Declaration
public AnalogLightSensor.Calibration LuminanceCalibration { get; protected set; }

Property Value

Type Description
AnalogLightSensor.Calibration

Remarks

AnalogLightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogLightSensor analogLightSensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    // configure our AnalogLightSensor sensor
    analogLightSensor = new AnalogLightSensor(
        analogPin: Device.Pins.A03);

    //==== IObservable Pattern with an optional notification filter.
    var consumer = AnalogLightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Lux:N2} lux, old: {result.Old.Value.Lux:N2} lux"),

        // only notify if the change is greater than 0.5
        filter: result => {
            if (result.Old is { } old) 
            {   //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Lux > 0.5; // returns true if > 0.5  change.
            }
            return false;
        }
        // if you want to always get notified, pass null for the filter:
        //filter: null
    );
    analogLightSensor.Subscribe(consumer);

    // classical .NET events can also be used:
    analogLightSensor.LuminosityUpdated += (sender, result) => 
        Resolver.Log.Info($"Lux changed: {result.New.Lux:N2} lux, old: {result.Old?.Lux:N2} lux");

    //==== One-off reading use case/pattern
    ReadIlluminance().Wait();

    // Spin up the sampling thread so that events are raised and IObservable notifications are sent.
    analogLightSensor.StartUpdating(TimeSpan.FromMilliseconds(1000));

    return Task.CompletedTask;
}

protected async Task ReadIlluminance()
{
    var illuminance = await analogLightSensor.Read();
    Resolver.Log.Info($"Initial lux: {illuminance.Lux:N2} lux");
}

Sample project(s) available on GitHub

Methods

RaiseEventsAndNotify(IChangeResult<Illuminance>)

Notify subscibers of LuminosityUpdated event hander

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<Illuminance> changeResult)

Parameters

Type Name Description
IChangeResult<Illuminance> changeResult

Change result with old and new Illuminance

Overrides

Remarks

AnalogLightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogLightSensor analogLightSensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    // configure our AnalogLightSensor sensor
    analogLightSensor = new AnalogLightSensor(
        analogPin: Device.Pins.A03);

    //==== IObservable Pattern with an optional notification filter.
    var consumer = AnalogLightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Lux:N2} lux, old: {result.Old.Value.Lux:N2} lux"),

        // only notify if the change is greater than 0.5
        filter: result => {
            if (result.Old is { } old) 
            {   //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Lux > 0.5; // returns true if > 0.5  change.
            }
            return false;
        }
        // if you want to always get notified, pass null for the filter:
        //filter: null
    );
    analogLightSensor.Subscribe(consumer);

    // classical .NET events can also be used:
    analogLightSensor.LuminosityUpdated += (sender, result) => 
        Resolver.Log.Info($"Lux changed: {result.New.Lux:N2} lux, old: {result.Old?.Lux:N2} lux");

    //==== One-off reading use case/pattern
    ReadIlluminance().Wait();

    // Spin up the sampling thread so that events are raised and IObservable notifications are sent.
    analogLightSensor.StartUpdating(TimeSpan.FromMilliseconds(1000));

    return Task.CompletedTask;
}

protected async Task ReadIlluminance()
{
    var illuminance = await analogLightSensor.Read();
    Resolver.Log.Info($"Initial lux: {illuminance.Lux:N2} lux");
}

Sample project(s) available on GitHub

ReadSensor()

Convenience method to get the current luminance. For frequent reads, use StartSampling() and StopSampling() in conjunction with the SampleBuffer.

Declaration
protected override Task<Illuminance> ReadSensor()

Returns

Type Description
Task<Illuminance>

Overrides

Remarks

AnalogLightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogLightSensor analogLightSensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    // configure our AnalogLightSensor sensor
    analogLightSensor = new AnalogLightSensor(
        analogPin: Device.Pins.A03);

    //==== IObservable Pattern with an optional notification filter.
    var consumer = AnalogLightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Lux:N2} lux, old: {result.Old.Value.Lux:N2} lux"),

        // only notify if the change is greater than 0.5
        filter: result => {
            if (result.Old is { } old) 
            {   //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Lux > 0.5; // returns true if > 0.5  change.
            }
            return false;
        }
        // if you want to always get notified, pass null for the filter:
        //filter: null
    );
    analogLightSensor.Subscribe(consumer);

    // classical .NET events can also be used:
    analogLightSensor.LuminosityUpdated += (sender, result) => 
        Resolver.Log.Info($"Lux changed: {result.New.Lux:N2} lux, old: {result.Old?.Lux:N2} lux");

    //==== One-off reading use case/pattern
    ReadIlluminance().Wait();

    // Spin up the sampling thread so that events are raised and IObservable notifications are sent.
    analogLightSensor.StartUpdating(TimeSpan.FromMilliseconds(1000));

    return Task.CompletedTask;
}

protected async Task ReadIlluminance()
{
    var illuminance = await analogLightSensor.Read();
    Resolver.Log.Info($"Initial lux: {illuminance.Lux:N2} lux");
}

Sample project(s) available on GitHub

StartUpdating(TimeSpan?)

Starts continuously sampling the sensor.

This method also starts raising Changed events and IObservable subscribers getting notified. Use the readIntervalDuration parameter to specify how often events and notifications are raised/sent.

Declaration
public override void StartUpdating(TimeSpan? updateInterval)

Parameters

Type Name Description
TimeSpan? updateInterval

A TimeSpan that specifies how long to wait between readings. This value influences how often *Updated events are raised and IObservable consumers are notified. The default is 5 seconds.

Overrides

Remarks

AnalogLightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogLightSensor analogLightSensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    // configure our AnalogLightSensor sensor
    analogLightSensor = new AnalogLightSensor(
        analogPin: Device.Pins.A03);

    //==== IObservable Pattern with an optional notification filter.
    var consumer = AnalogLightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Lux:N2} lux, old: {result.Old.Value.Lux:N2} lux"),

        // only notify if the change is greater than 0.5
        filter: result => {
            if (result.Old is { } old) 
            {   //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Lux > 0.5; // returns true if > 0.5  change.
            }
            return false;
        }
        // if you want to always get notified, pass null for the filter:
        //filter: null
    );
    analogLightSensor.Subscribe(consumer);

    // classical .NET events can also be used:
    analogLightSensor.LuminosityUpdated += (sender, result) => 
        Resolver.Log.Info($"Lux changed: {result.New.Lux:N2} lux, old: {result.Old?.Lux:N2} lux");

    //==== One-off reading use case/pattern
    ReadIlluminance().Wait();

    // Spin up the sampling thread so that events are raised and IObservable notifications are sent.
    analogLightSensor.StartUpdating(TimeSpan.FromMilliseconds(1000));

    return Task.CompletedTask;
}

protected async Task ReadIlluminance()
{
    var illuminance = await analogLightSensor.Read();
    Resolver.Log.Info($"Initial lux: {illuminance.Lux:N2} lux");
}

Sample project(s) available on GitHub

StopUpdating()

Stops sampling the temperature.

Declaration
public override void StopUpdating()

Overrides

Remarks

AnalogLightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogLightSensor analogLightSensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    // configure our AnalogLightSensor sensor
    analogLightSensor = new AnalogLightSensor(
        analogPin: Device.Pins.A03);

    //==== IObservable Pattern with an optional notification filter.
    var consumer = AnalogLightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Lux:N2} lux, old: {result.Old.Value.Lux:N2} lux"),

        // only notify if the change is greater than 0.5
        filter: result => {
            if (result.Old is { } old) 
            {   //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Lux > 0.5; // returns true if > 0.5  change.
            }
            return false;
        }
        // if you want to always get notified, pass null for the filter:
        //filter: null
    );
    analogLightSensor.Subscribe(consumer);

    // classical .NET events can also be used:
    analogLightSensor.LuminosityUpdated += (sender, result) => 
        Resolver.Log.Info($"Lux changed: {result.New.Lux:N2} lux, old: {result.Old?.Lux:N2} lux");

    //==== One-off reading use case/pattern
    ReadIlluminance().Wait();

    // Spin up the sampling thread so that events are raised and IObservable notifications are sent.
    analogLightSensor.StartUpdating(TimeSpan.FromMilliseconds(1000));

    return Task.CompletedTask;
}

protected async Task ReadIlluminance()
{
    var illuminance = await analogLightSensor.Read();
    Resolver.Log.Info($"Initial lux: {illuminance.Lux:N2} lux");
}

Sample project(s) available on GitHub

VoltageToLuminance(Voltage)

Converts a voltage value to a level in centimeters, based on the current calibration values.

Declaration
protected Illuminance VoltageToLuminance(Voltage voltage)

Parameters

Type Name Description
Voltage voltage

Returns

Type Description
Illuminance

Remarks

AnalogLightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogLightSensor analogLightSensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    // configure our AnalogLightSensor sensor
    analogLightSensor = new AnalogLightSensor(
        analogPin: Device.Pins.A03);

    //==== IObservable Pattern with an optional notification filter.
    var consumer = AnalogLightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Lux:N2} lux, old: {result.Old.Value.Lux:N2} lux"),

        // only notify if the change is greater than 0.5
        filter: result => {
            if (result.Old is { } old) 
            {   //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Lux > 0.5; // returns true if > 0.5  change.
            }
            return false;
        }
        // if you want to always get notified, pass null for the filter:
        //filter: null
    );
    analogLightSensor.Subscribe(consumer);

    // classical .NET events can also be used:
    analogLightSensor.LuminosityUpdated += (sender, result) => 
        Resolver.Log.Info($"Lux changed: {result.New.Lux:N2} lux, old: {result.Old?.Lux:N2} lux");

    //==== One-off reading use case/pattern
    ReadIlluminance().Wait();

    // Spin up the sampling thread so that events are raised and IObservable notifications are sent.
    analogLightSensor.StartUpdating(TimeSpan.FromMilliseconds(1000));

    return Task.CompletedTask;
}

protected async Task ReadIlluminance()
{
    var illuminance = await analogLightSensor.Read();
    Resolver.Log.Info($"Initial lux: {illuminance.Lux:N2} lux");
}

Sample project(s) available on GitHub

Events

LuminosityUpdated

Raised when the value of the reading changes.

Declaration
public event EventHandler<IChangeResult<Illuminance>> LuminosityUpdated

Event Type

Type Description
EventHandler<IChangeResult<Illuminance>>

Remarks

AnalogLightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

Code Example

AnalogLightSensor analogLightSensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    // configure our AnalogLightSensor sensor
    analogLightSensor = new AnalogLightSensor(
        analogPin: Device.Pins.A03);

    //==== IObservable Pattern with an optional notification filter.
    var consumer = AnalogLightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Lux:N2} lux, old: {result.Old.Value.Lux:N2} lux"),

        // only notify if the change is greater than 0.5
        filter: result => {
            if (result.Old is { } old) 
            {   //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Lux > 0.5; // returns true if > 0.5  change.
            }
            return false;
        }
        // if you want to always get notified, pass null for the filter:
        //filter: null
    );
    analogLightSensor.Subscribe(consumer);

    // classical .NET events can also be used:
    analogLightSensor.LuminosityUpdated += (sender, result) => 
        Resolver.Log.Info($"Lux changed: {result.New.Lux:N2} lux, old: {result.Old?.Lux:N2} lux");

    //==== One-off reading use case/pattern
    ReadIlluminance().Wait();

    // Spin up the sampling thread so that events are raised and IObservable notifications are sent.
    analogLightSensor.StartUpdating(TimeSpan.FromMilliseconds(1000));

    return Task.CompletedTask;
}

protected async Task ReadIlluminance()
{
    var illuminance = await analogLightSensor.Read();
    Resolver.Log.Info($"Initial lux: {illuminance.Lux:N2} lux");
}

Sample project(s) available on GitHub