Meadow.Foundation.Grove.Sensors.Environmental.WaterSensor
WaterSensor | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
Code Example
WaterSensor waterSensor;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
waterSensor = new WaterSensor(Device.Pins.A01);
waterSensor.Subscribe(WaterSensor.CreateObserver(
h => Resolver.Log.Info($"Water level changed by 10 mm; new: {h.New}, old: {h.Old}"),
null //e => { return Math.Abs(e.Delta) > 0.1f; }
));
waterSensor.Updated += (object sender, IChangeResult<float> e) =>
{
Resolver.Log.Info($"Level Changed, level: {e.New}cm");
};
return Task.CompletedTask;
}
public override async Task Run()
{
var conditions = await waterSensor.Read();
Resolver.Log.Info($"Initial level: {conditions}");
waterSensor.StartUpdating(TimeSpan.FromSeconds(5));
}
Sample project(s) available on GitHub
Wiring Example
WaterSensor | Meadow Pin |
---|---|
GND | GND |
VCC | 3.3V |
RX | D01 |
TX | D00 |
Class WaterSensor
Represents a water sensor that can detect the level of water.
Assembly: WaterSensor.dll
View Source
Declaration
public class WaterSensor : AnalogWaterLevel, IObservable<IChangeResult<float>>, ISamplingSensor<float>, ISensor<float>, ISensor, ISamplingSensor
Inheritance: System.Object
-> Meadow.Foundation.ObservableBase<System.Single>
-> Meadow.Foundation.SamplingSensorBase<System.Single>
-> Meadow.Foundation.Sensors.Environmental.AnalogWaterLevel
Implements:
System.IObservable<Meadow.IChangeResult<System.Single>>
, Meadow.Peripherals.Sensors.ISamplingSensor<System.Single>
, Meadow.Peripherals.Sensors.ISensor<System.Single>
, Meadow.Peripherals.Sensors.ISensor
, Meadow.Peripherals.Sensors.ISamplingSensor
Implements
System.IObservable<Meadow.IChangeResult<System.Single>>
Meadow.Peripherals.Sensors.ISamplingSensor<System.Single>
Meadow.Peripherals.Sensors.ISensor<System.Single>
Meadow.Peripherals.Sensors.ISensor
Meadow.Peripherals.Sensors.ISamplingSensor