public override void OnInspectorGUI() { this.serializedObject.Update(); HCSR04 controller = (HCSR04)target; GUI.enabled = false; EditorGUILayout.PropertyField(script, true, new GUILayoutOption[0]); GUI.enabled = true; foldout = EditorGUILayout.Foldout(foldout, "Sketch Options"); if (foldout) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(id, new GUIContent("id")); EditorGUILayout.PropertyField(trig, new GUIContent("trig")); EditorGUILayout.PropertyField(echo, new GUIContent("echo")); EditorGUI.indentLevel--; } controller.enableUpdate = EditorGUILayout.Toggle("Enable update", controller.enableUpdate); EditorGUILayout.LabelField(string.Format("Distance: {0:f1}cm", controller.distance)); if (Application.isPlaying && controller.enableUpdate) { EditorUtility.SetDirty(target); } this.serializedObject.ApplyModifiedProperties(); }
private void Initialize() { //initialize the motors. motorA = new GpioMotorController(motorAForwardPin, motorABackPin); motorB = new GpioMotorController(motorBForwardPin, motorBBackPin); //initialize our senses. distanceSensor = new HCSR04(triggerPin, echoPin); this.Stop(); this.CurrentState = CarState.Stopped; }
public MeadowApp() { hCSR04 = new HCSR04(Device, Device.Pins.D05, Device.Pins.D06); hCSR04.DistanceDetected += HCSR04DistanceDetected; while (true) { // Sends a trigger signal hCSR04.MeasureDistance(); Thread.Sleep(1500); } }
public static void Main() { var _HCSR04 = new HCSR04(Pins.GPIO_PIN_D12, Pins.GPIO_PIN_D11); _HCSR04.DistanceDetected += OnDistanceDetected; while (true) { // Send a echo _HCSR04.MeasureDistance(); Thread.Sleep(500); } }
public void Run(IBackgroundTaskInstance taskInstance) { try { hcsr04 = new HCSR04(12, 36); } catch (Exception ex) { Debug.WriteLine(ex.Message); } hcsr04InputPollingTimer = new Timer(SensorUpdateTimerCallback, null, timerDue, timerPeriod); backgroundTaskDeferral = taskInstance.GetDeferral(); }
public CommandProcessor( Arduino.Arduino arduino, DisplayManager displayManager, PlaybackService playbackService, HttpServer httpServer, PanTiltServo panTiltServo, HCSR04 ultrasonicsensor) { this.arduino = arduino; this.displayManager = displayManager; this.playbackService = playbackService; this.httpServer = httpServer; this.panTiltServo = panTiltServo; this.ultrasonicsensor = ultrasonicsensor; this.arduino.I2CDataReceived += this.Arduino_I2CDataReceived; this.httpServer.NotifyCallerEventHandler += this.NotifyOnObstacleEventHandler; }
public ManDetectionDistanceSensor(IGpioController gpio) { mDistanceSensor = new HCSR04(gpio, TRIGGER_PIN, ECHO_PIN, Length.FromMeters(3.0)); }
public static void DistanceMeasuring( State state, object stateLock, FPGA.InputSignal <bool> echo, FPGA.OutputSignal <bool> trigger ) { ushort[] buff = new ushort[10]; int addr = 0; bool filled = false; Sequential measureHandler = () => { ushort distance = 0; HCSR04.Measure(echo, trigger, out distance); buff[addr] = distance; addr++; if (addr == buff.Length) { filled = true; addr = 0; } state.Current = distance; if (filled) { // get averange of distances Filters.Average(buff, out state.Average); if (state.Average < 50) { state.DistanceState = ProximityState.Alert; } else if (state.Average < 150) { state.DistanceState = ProximityState.Warning; } else { state.DistanceState = ProximityState.Safe; } if (state.Average < 200) { if (state.Average > (state.LastMaxDistance + 10)) { state.LastMaxDistance = state.Average; lock (stateLock) { state.RaiseGoneNotification = true; } } else if (state.Average < (state.LastMaxDistance - 5)) { state.LastMaxDistance = state.Average; } } else { state.LastMaxDistance = state.Average; } } else { state.DistanceState = ProximityState.Measuring; } }; FPGA.Config.OnTimer(TimeSpan.FromMilliseconds(200), measureHandler); }