Skip to main content

Meadow.Foundation.Sensors.Distance.Me007ys

Me007ys
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Distance.Me007ys

Code Example

Me007ys me007ys;

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

me007ys = new Me007ys(Device, Device.PlatformOS.GetSerialPortName("COM1"));

var consumer = Me007ys.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: Distance changed by threshold; new distance: {result.New.Centimeters:N1}cm, old: {result.Old?.Centimeters:N1}cm");
},
filter: result =>
{
if (result.Old is { } old)
{
return Math.Abs((result.New - old).Centimeters) > 5.0;
}
return false;
}
);
me007ys.Subscribe(consumer);

me007ys.Updated += Me007y_DistanceUpdated;

return Task.CompletedTask;
}

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

var distance = await me007ys.Read();
Resolver.Log.Info($"Initial distance is: {distance.Centimeters:N1}cm / {distance.Inches:N1}in");

me007ys.StartUpdating(TimeSpan.FromSeconds(2));
}

private void Me007y_DistanceUpdated(object sender, IChangeResult<Length> e)
{
Resolver.Log.Info($"Distance: {e.New.Centimeters:N1}cm / {e.New.Inches:N1}in");
}

Sample project(s) available on GitHub