Remarks
SoundSensor | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
Code Example
SoundSensor sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// configure our sensor
sensor = new SoundSensor(Device.Pins.A01);
var consumer = SoundSensor.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
LoudnessSensor | Meadow Pin |
---|---|
GND | GND |
VCC | 3.3V |
RX | D01 |
TX | D00 |
Syntax
public class LoudnessSensor : AnalogSamplingBase, IObservable<IChangeResult<Voltage>>, ISamplingSensor<Voltage>, ISensor<Voltage>
Constructors
LoudnessSensor(IAnalogInputPort)
Creates a new LoudnessSensor driver
Declaration
public LoudnessSensor(IAnalogInputPort port)
Parameters
Type | Name | Description |
---|---|---|
IAnalogInputPort | port |
Remarks
SoundSensor | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
Code Example
SoundSensor sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// configure our sensor
sensor = new SoundSensor(Device.Pins.A01);
var consumer = SoundSensor.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
LoudnessSensor | Meadow Pin |
---|---|
GND | GND |
VCC | 3.3V |
RX | D01 |
TX | D00 |
LoudnessSensor(IPin, int, TimeSpan?, Voltage?)
Creates a new LoudnessSensor driver
Declaration
public LoudnessSensor(IPin pin, int sampleCount = 5, TimeSpan? sampleInterval = null, Voltage? voltage = null)
Parameters
Type | Name | Description |
---|---|---|
IPin | pin | AnalogChannel connected to the sensor. |
int | sampleCount | |
TimeSpan? | sampleInterval | |
Voltage? | voltage |
Remarks
SoundSensor | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
Code Example
SoundSensor sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// configure our sensor
sensor = new SoundSensor(Device.Pins.A01);
var consumer = SoundSensor.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
LoudnessSensor | Meadow Pin |
---|---|
GND | GND |
VCC | 3.3V |
RX | D01 |
TX | D00 |