Skip to main content

Meadow.Foundation.Grove.Sensors.Rotary.RotaryAngleSensor

RotaryAngleSensor
StatusStatus badge: working
Source codeGitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Grove.Sensors.Rotary.RotaryAngleSensor

Code Example

RotaryAngleSensor sensor;

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

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

var consumer = RotaryAngleSensor.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

RotaryAngleSensorMeadow Pin
GNDGND
VCC3.3V
RXD01
TXD00

Class RotaryAngleSensor

Represents a rotary angle sensor

Assembly: RotaryAngleSensor.dll
View Source
Declaration
public class RotaryAngleSensor : AnalogSamplingBase, IObservable<IChangeResult<Voltage>>, ISamplingSensor<Voltage>, ISensor<Voltage>, ISensor, ISamplingSensor

Inheritance: System.Object -> Meadow.Foundation.ObservableBase<Meadow.Units.Voltage> -> Meadow.Foundation.SamplingSensorBase<Meadow.Units.Voltage> -> Meadow.Foundation.Sensors.Base.AnalogSamplingBase

Implements:
System.IObservable<Meadow.IChangeResult<Meadow.Units.Voltage>>, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Voltage>, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Voltage>, Meadow.Peripherals.Sensors.ISensor, Meadow.Peripherals.Sensors.ISamplingSensor

Implements

  • System.IObservable<Meadow.IChangeResult<Meadow.Units.Voltage>>
  • Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Voltage>
  • Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Voltage>
  • Meadow.Peripherals.Sensors.ISensor
  • Meadow.Peripherals.Sensors.ISamplingSensor