Remarks

Alspt19315C
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Alspt19315C

The ALS-PT19-315C is a low cost analog ambient light sensor, consisting of phototransistor in a miniature SMD.

Code Example

Alspt19315C sensor;

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

    // configure our sensor
    sensor = new Alspt19315C(Device.Pins.A03);

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

        // only notify if the change is greater than 0.5V
        filter: result =>
        {
            if (result.Old is { } old)
            {
                return (result.New - old).Abs().Volts > 0.5; // returns true if > 0.5V change.
            }
            return false;
        }
    );
    sensor.Subscribe(consumer);

    //==== Classic Events Pattern
    sensor.Updated += (sender, result) =>
    {
        Resolver.Log.Info($"Voltage Changed, new: {result.New.Volts:N2}V, old: {result.Old?.Volts:N2}V");
    };

    return Task.CompletedTask;
}

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

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

Sample project(s) available on GitHub

Wiring Example

The ALS-PT19C is a simple analog device requiring only three connections:

Characteristic Locus
Inheritance object ObservableBase<Voltage> SamplingSensorBase<Voltage> > Alspt19315C
Implements IObservable<IChangeResult<Voltage>> ISamplingSensor<Voltage> ISensor<Voltage>
Inherited Members SamplingSensorBase<Voltage>.samplingLock SamplingSensorBase<Voltage>.Updated SamplingSensorBase<Voltage>.SamplingTokenSource SamplingSensorBase<Voltage>.Conditions SamplingSensorBase<Voltage>.IsSampling SamplingSensorBase<Voltage>.UpdateInterval SamplingSensorBase<Voltage>.RaiseEventsAndNotify(IChangeResult<Voltage>) SamplingSensorBase<Voltage>.Read() ObservableBase<Voltage>.observers ObservableBase<Voltage>.NotifyObservers(IChangeResult<Voltage>) ObservableBase<Voltage>.Subscribe(IObserver<IChangeResult<Voltage>>) ObservableBase<Voltage>.CreateObserver(Action<IChangeResult<Voltage>>, Predicate<IChangeResult<Voltage>>) 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 Alspt19315C.dll

Syntax

public class Alspt19315C : SamplingSensorBase<Voltage>, IObservable<IChangeResult<Voltage>>, ISamplingSensor<Voltage>, ISensor<Voltage>

Constructors

Alspt19315C(IAnalogInputPort)

Create a new light sensor object using a static reference voltage

Declaration
public Alspt19315C(IAnalogInputPort port)

Parameters

Type Name Description
IAnalogInputPort port

Remarks

Alspt19315C
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Alspt19315C

The ALS-PT19-315C is a low cost analog ambient light sensor, consisting of phototransistor in a miniature SMD.

Code Example

Alspt19315C sensor;

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

    // configure our sensor
    sensor = new Alspt19315C(Device.Pins.A03);

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

        // only notify if the change is greater than 0.5V
        filter: result =>
        {
            if (result.Old is { } old)
            {
                return (result.New - old).Abs().Volts > 0.5; // returns true if > 0.5V change.
            }
            return false;
        }
    );
    sensor.Subscribe(consumer);

    //==== Classic Events Pattern
    sensor.Updated += (sender, result) =>
    {
        Resolver.Log.Info($"Voltage Changed, new: {result.New.Volts:N2}V, old: {result.Old?.Volts:N2}V");
    };

    return Task.CompletedTask;
}

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

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

Sample project(s) available on GitHub

Wiring Example

The ALS-PT19C is a simple analog device requiring only three connections:

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

Create a new light sensor object using a static reference voltage

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

Parameters

Type Name Description
IPin pin

The analog pin

int sampleCount

The sample count

TimeSpan? sampleInterval

The sample interval

Voltage? voltage

The peak voltage

Remarks

Alspt19315C
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Alspt19315C

The ALS-PT19-315C is a low cost analog ambient light sensor, consisting of phototransistor in a miniature SMD.

Code Example

Alspt19315C sensor;

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

    // configure our sensor
    sensor = new Alspt19315C(Device.Pins.A03);

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

        // only notify if the change is greater than 0.5V
        filter: result =>
        {
            if (result.Old is { } old)
            {
                return (result.New - old).Abs().Volts > 0.5; // returns true if > 0.5V change.
            }
            return false;
        }
    );
    sensor.Subscribe(consumer);

    //==== Classic Events Pattern
    sensor.Updated += (sender, result) =>
    {
        Resolver.Log.Info($"Voltage Changed, new: {result.New.Volts:N2}V, old: {result.Old?.Volts:N2}V");
    };

    return Task.CompletedTask;
}

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

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

Sample project(s) available on GitHub

Wiring Example

The ALS-PT19C is a simple analog device requiring only three connections:

Properties

Voltage

The current voltage reading of the sensor

Declaration
public Voltage Voltage { get; protected set; }

Property Value

Type Description
Voltage

Remarks

Alspt19315C
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Alspt19315C

The ALS-PT19-315C is a low cost analog ambient light sensor, consisting of phototransistor in a miniature SMD.

Code Example

Alspt19315C sensor;

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

    // configure our sensor
    sensor = new Alspt19315C(Device.Pins.A03);

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

        // only notify if the change is greater than 0.5V
        filter: result =>
        {
            if (result.Old is { } old)
            {
                return (result.New - old).Abs().Volts > 0.5; // returns true if > 0.5V change.
            }
            return false;
        }
    );
    sensor.Subscribe(consumer);

    //==== Classic Events Pattern
    sensor.Updated += (sender, result) =>
    {
        Resolver.Log.Info($"Voltage Changed, new: {result.New.Volts:N2}V, old: {result.Old?.Volts:N2}V");
    };

    return Task.CompletedTask;
}

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

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

Sample project(s) available on GitHub

Wiring Example

The ALS-PT19C is a simple analog device requiring only three connections:

Methods

ReadSensor()

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

Declaration
protected override Task<Voltage> ReadSensor()

Returns

Type Description
Task<Voltage>

A float value that's an average value of all the samples taken.

Overrides

Remarks

Alspt19315C
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Alspt19315C

The ALS-PT19-315C is a low cost analog ambient light sensor, consisting of phototransistor in a miniature SMD.

Code Example

Alspt19315C sensor;

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

    // configure our sensor
    sensor = new Alspt19315C(Device.Pins.A03);

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

        // only notify if the change is greater than 0.5V
        filter: result =>
        {
            if (result.Old is { } old)
            {
                return (result.New - old).Abs().Volts > 0.5; // returns true if > 0.5V change.
            }
            return false;
        }
    );
    sensor.Subscribe(consumer);

    //==== Classic Events Pattern
    sensor.Updated += (sender, result) =>
    {
        Resolver.Log.Info($"Voltage Changed, new: {result.New.Volts:N2}V, old: {result.Old?.Volts:N2}V");
    };

    return Task.CompletedTask;
}

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

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

Sample project(s) available on GitHub

Wiring Example

The ALS-PT19C is a simple analog device requiring only three connections:

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.

Overrides

Remarks

Alspt19315C
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Alspt19315C

The ALS-PT19-315C is a low cost analog ambient light sensor, consisting of phototransistor in a miniature SMD.

Code Example

Alspt19315C sensor;

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

    // configure our sensor
    sensor = new Alspt19315C(Device.Pins.A03);

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

        // only notify if the change is greater than 0.5V
        filter: result =>
        {
            if (result.Old is { } old)
            {
                return (result.New - old).Abs().Volts > 0.5; // returns true if > 0.5V change.
            }
            return false;
        }
    );
    sensor.Subscribe(consumer);

    //==== Classic Events Pattern
    sensor.Updated += (sender, result) =>
    {
        Resolver.Log.Info($"Voltage Changed, new: {result.New.Volts:N2}V, old: {result.Old?.Volts:N2}V");
    };

    return Task.CompletedTask;
}

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

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

Sample project(s) available on GitHub

Wiring Example

The ALS-PT19C is a simple analog device requiring only three connections:

StopUpdating()

Stops sampling the sensor

Declaration
public override void StopUpdating()

Overrides

Remarks

Alspt19315C
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Light.Alspt19315C

The ALS-PT19-315C is a low cost analog ambient light sensor, consisting of phototransistor in a miniature SMD.

Code Example

Alspt19315C sensor;

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

    // configure our sensor
    sensor = new Alspt19315C(Device.Pins.A03);

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

        // only notify if the change is greater than 0.5V
        filter: result =>
        {
            if (result.Old is { } old)
            {
                return (result.New - old).Abs().Volts > 0.5; // returns true if > 0.5V change.
            }
            return false;
        }
    );
    sensor.Subscribe(consumer);

    //==== Classic Events Pattern
    sensor.Updated += (sender, result) =>
    {
        Resolver.Log.Info($"Voltage Changed, new: {result.New.Volts:N2}V, old: {result.Old?.Volts:N2}V");
    };

    return Task.CompletedTask;
}

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

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

Sample project(s) available on GitHub

Wiring Example

The ALS-PT19C is a simple analog device requiring only three connections: