Remarks

LightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Grove.Sensors.Light.LightSensor

Code Example

LightSensor sensor;

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

    sensor = new LightSensor(Device.Pins.A01);

    var consumer = LightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Millivolts:N2}mV, old: {result.Old?.Millivolts:N2}mV"),
        filter: result =>
        {
            if (result.Old is { } old)
            { //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Millivolts > 500;
            }
            return false;
        });

    sensor.Subscribe(consumer);

    sensor.Updated += (sender, result) =>
    {
        Resolver.Log.Info($"Voltage Changed, new: {result.New.Millivolts:N2}mV, old: {result.Old?.Millivolts:N2}mV");
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Resolver.Log.Info($"Initial read: {result.Millivolts:N2}mV");

    sensor.StartUpdating(TimeSpan.FromMilliseconds(1000));
}

Sample project(s) available on GitHub

Wiring Example

LightSensor Meadow Pin
GND GND
VCC 3.3V
RX D01
TX D00
Characteristic Locus
Inheritance object ObservableBase<Voltage> SamplingSensorBase<Voltage> AnalogSamplingBase > LightSensor
Implements IObservable<IChangeResult<Voltage>> ISamplingSensor<Voltage> ISensor<Voltage>
Inherited Members AnalogSamplingBase.StartUpdating(TimeSpan?) AnalogSamplingBase.StopUpdating() AnalogSamplingBase.ReadSensor() AnalogSamplingBase.Voltage SamplingSensorBase<Voltage>.samplingLock SamplingSensorBase<Voltage>.RaiseEventsAndNotify(IChangeResult<Voltage>) SamplingSensorBase<Voltage>.Read() SamplingSensorBase<Voltage>.SamplingTokenSource SamplingSensorBase<Voltage>.Conditions SamplingSensorBase<Voltage>.IsSampling SamplingSensorBase<Voltage>.UpdateInterval SamplingSensorBase<Voltage>.Updated ObservableBase<Voltage>.NotifyObservers(IChangeResult<Voltage>) ObservableBase<Voltage>.Subscribe(IObserver<IChangeResult<Voltage>>) ObservableBase<Voltage>.CreateObserver(Action<IChangeResult<Voltage>>, Predicate<IChangeResult<Voltage>>) ObservableBase<Voltage>.observers object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString()
Namespace Meadow.Foundation.Grove.Sensors.Light
Assembly LightSensor.dll

Syntax

public class LightSensor : AnalogSamplingBase, IObservable<IChangeResult<Voltage>>, ISamplingSensor<Voltage>, ISensor<Voltage>

Constructors

LightSensor(IAnalogInputPort)

Creates a new LightSensor driver

Declaration
public LightSensor(IAnalogInputPort port)

Parameters

Type Name Description
IAnalogInputPort port

Remarks

LightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Grove.Sensors.Light.LightSensor

Code Example

LightSensor sensor;

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

    sensor = new LightSensor(Device.Pins.A01);

    var consumer = LightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Millivolts:N2}mV, old: {result.Old?.Millivolts:N2}mV"),
        filter: result =>
        {
            if (result.Old is { } old)
            { //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Millivolts > 500;
            }
            return false;
        });

    sensor.Subscribe(consumer);

    sensor.Updated += (sender, result) =>
    {
        Resolver.Log.Info($"Voltage Changed, new: {result.New.Millivolts:N2}mV, old: {result.Old?.Millivolts:N2}mV");
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Resolver.Log.Info($"Initial read: {result.Millivolts:N2}mV");

    sensor.StartUpdating(TimeSpan.FromMilliseconds(1000));
}

Sample project(s) available on GitHub

Wiring Example

LightSensor Meadow Pin
GND GND
VCC 3.3V
RX D01
TX D00

LightSensor(IPin, int, TimeSpan?, Voltage?)

Creates a new LightSensor driver

Declaration
public LightSensor(IPin pin, int sampleCount = 5, TimeSpan? sampleInterval = null, Voltage? voltage = null)

Parameters

Type Name Description
IPin pin
int sampleCount
TimeSpan? sampleInterval
Voltage? voltage

Remarks

LightSensor
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Grove.Sensors.Light.LightSensor

Code Example

LightSensor sensor;

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

    sensor = new LightSensor(Device.Pins.A01);

    var consumer = LightSensor.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer filter satisfied: {result.New.Millivolts:N2}mV, old: {result.Old?.Millivolts:N2}mV"),
        filter: result =>
        {
            if (result.Old is { } old)
            { //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Abs().Millivolts > 500;
            }
            return false;
        });

    sensor.Subscribe(consumer);

    sensor.Updated += (sender, result) =>
    {
        Resolver.Log.Info($"Voltage Changed, new: {result.New.Millivolts:N2}mV, old: {result.Old?.Millivolts:N2}mV");
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    var result = await sensor.Read();
    Resolver.Log.Info($"Initial read: {result.Millivolts:N2}mV");

    sensor.StartUpdating(TimeSpan.FromMilliseconds(1000));
}

Sample project(s) available on GitHub

Wiring Example

LightSensor Meadow Pin
GND GND
VCC 3.3V
RX D01
TX D00