public VM_UltraSonicControllerMain() { //Create an ultra sonic sensor using GPIO Pin 20 for trigger and 21 for echo _ultraSonicSensor = new UltraSonicSensor((int)RaspberryPiGPI0Pin.GPIO20, (int)RaspberryPiGPI0Pin.GPIO21); if (AnalyticsInfo.VersionInfo.DeviceFamily != "Windows.Desktop") { Task.Run(async() => { while (true) { await Task.Delay(50); await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { DistanceInInches = ((int)_ultraSonicSensor.GetDistanceInInches).ToString(); }); } } ); } else { DistanceInInches = "54321"; } }
public UltraSonicSensorExample() { IUltraSonicSensor encoder = new UltraSonicSensor(Connectors.GPIO23, Connectors.GPIO24); encoder.Start(); while (true) { Console.WriteLine("Distance: {0} cm", encoder.Distance.ToString("0.##")); Thread.Sleep(1000); } }
private static void TestUltrasound() { UltraSonicSensor ultraSonic = new UltraSonicSensor(_goPiGo3, GrovePort.Grove1); Console.WriteLine($"Test {ultraSonic.SensorName} on port {ultraSonic.Port}. Gives the distance. Press enter to stop the test."); AddLines(); while (!Console.KeyAvailable) { Console.CursorLeft = 0; Console.Write($"Value: {ultraSonic.Value}, ValueAsString: {ultraSonic.ToString()}"); Thread.Sleep(100); CleanALine(); } }
static void UltrasonicSensor() { UltraSonicSensor sensor = new UltraSonicSensor(21, 20, 2000); while (true) { if (sensor.ReadDistance() == false) { Console.WriteLine("Error"); } else { Console.WriteLine(String.Format("Milliseconds: {0:0.0000}", sensor.Milliseconds)); Console.WriteLine(String.Format("Distance: {0:0.0} cm", sensor.Distance)); Console.ReadLine(); } } }
static void UltrasonicSensorDisplay1602() { UltraSonicSensor sensor = new UltraSonicSensor(21, 20, 2000); Display1602 display = new Display1602(16, 12, 26, 25, 24, 23); display.Clear(); while (true) { if (sensor.ReadDistance() == false) { Console.WriteLine("Error"); } else { Console.WriteLine(String.Format("Milliseconds: {0:0.0000}", sensor.Milliseconds)); Console.WriteLine(String.Format("Distance: {0:0.0} cm", sensor.Distance)); display.SetCursor(1, 1); display.Write(String.Format("Ms: {0:0.0000}", sensor.Milliseconds)); display.SetCursor(1, 2); display.Write(String.Format("Dt: {0:0.0} cm", sensor.Distance)); Console.ReadLine(); } } }