private void InitGPIO() { var gpio = GpioController.GetDefault(); // Show an error if there is no GPIO controller if (gpio == null) { pin0 = null; pin1 = null; pin2 = null; pin3 = null; pin4 = null; pin5 = null; pin6 = null; pin7 = null; GpioStatus.Text = "There is no GPIO controller on this device."; return; } pin0 = gpio.OpenPin(LED_PIN0); pin0.SetDriveMode(GpioPinDriveMode.Input); pinValue0 = pin0.Read(); pin1 = gpio.OpenPin(LED_PIN1); pin1.SetDriveMode(GpioPinDriveMode.Input); pinValue1 = pin1.Read(); pin2 = gpio.OpenPin(LED_PIN2); pin2.SetDriveMode(GpioPinDriveMode.Input); pinValue2 = pin2.Read(); pin3 = gpio.OpenPin(LED_PIN3); pin3.SetDriveMode(GpioPinDriveMode.Input); pinValue3 = pin3.Read(); pin4 = gpio.OpenPin(LED_PIN4); pin4.SetDriveMode(GpioPinDriveMode.Input); pinValue4 = pin4.Read(); pin5 = gpio.OpenPin(LED_PIN5); pin5.SetDriveMode(GpioPinDriveMode.Input); pinValue5 = pin5.Read(); pin6 = gpio.OpenPin(LED_PIN6); pin6.SetDriveMode(GpioPinDriveMode.Input); pinValue6 = pin6.Read(); pin7 = gpio.OpenPin(LED_PIN7); pin7.SetDriveMode(GpioPinDriveMode.Input); pinValue7 = pin7.Read(); //pin0.ValueChanged += Pin0_ValueChanged; GpioStatus.Text = "GPIO pin initialized correctly."; }
private void ValueChangedHandler(GpioPin sender, GpioPinValueChangedEventArgs args) { var pinNumber = sender.PinNumber; var gpioPinValue = sender.Read(); Debug.WriteLine("Pin {0} changed to {1}", pinNumber, gpioPinValue); if (pinNumber == TiltSensorPin) { _halper.DishwasherTilt(gpioPinValue == GpioPinValue.High); var currentStatus = _halper.Get().CurrentStatus; if (currentStatus == DishwasherStatus.Clean && gpioPinValue == GpioPinValue.High) { ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(10000)); } return; } var tiltSensorValue = _gpioSensors[TiltSensorPin].Read(); if (gpioPinValue == GpioPinValue.High) { if (pinNumber == CleanLightPin) { _halper.EndDishwasherRun(); } else if (tiltSensorValue == GpioPinValue.Low && _pinToCycleTypeMap.ContainsKey(pinNumber)) { _halper.StartDishwasherRun(_pinToCycleTypeMap[pinNumber]); } } }
private void InitGPIO() { var mygpio = GpioController.GetDefault(); // Show an error if there is no GPIO controller if (mygpio == null) { buttonPin = null; ledPin = null; return; } ledPin = mygpio.OpenPin(LEDPINNBR); ledPin.Write(GpioPinValue.Low); //initialize Led to On as wired in active Low config (+3.3-Led-GPIO) ledPin.SetDriveMode(GpioPinDriveMode.Output); buttonPin = mygpio.OpenPin(BUTTONPINNBR); //buttonPin.Write(GpioPinValue.High); //buttonPin.SetDriveMode(GpioPinDriveMode.Output); //buttonPinValCurrent = buttonPin.Read(); buttonPin.SetDriveMode(GpioPinDriveMode.Input); //buttonPinValPrior = GpioPinValue.High; Debug.WriteLine("ButtonPin Value at Init: " + buttonPin.Read() + ", with Pin ID = " + buttonPin.PinNumber); //buttonPinVal = buttonPin.Read(); // Set a debounce timeout to filter out switch bounce noise from a button press buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(20); // Register for the ValueChanged event so our buttonPin_ValueChanged // function is called when the button is pressed buttonPin.ValueChanged += buttonPressAction; }
private void ButtonPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args) { if (sender.Read() == GpioPinValue.High) { sendEvents = !sendEvents; if (sendEvents) { Task.Run(() => SendEvents()); } } }
private void FlipLed(GpioPin led) { if (adcValue == 0) { turnOnLed(led); return; } if (led.Read() == GpioPinValue.High) turnOnLed(led); else turnOffLed(led); }
public void InitalizeLed() { Debug.WriteLine("InternetLed::InitalizeLed"); // Now setup the LedControlPin gpio = GpioController.GetDefault(); LedControlGPIOPin = gpio.OpenPin(LedControlPin); LedControlGPIOPin.SetDriveMode(GpioPinDriveMode.Output); // Get the current pin value GpioPinValue startingValue = LedControlGPIOPin.Read(); _LedState = (startingValue == GpioPinValue.Low) ? eLedState.On : eLedState.Off; }
int RCTime(GpioPin pin, int max) { pin.SetDriveMode(GpioPinDriveMode.Output); pin.Write(GpioPinValue.Low); pin.SetDriveMode(GpioPinDriveMode.Input); int reading = 0; while (pin.Read() == GpioPinValue.Low) { reading++; if (reading >= max) break; } return reading; }
private double PulseIn(GpioPin pin, GpioPinValue value, ushort timeout) { sw.Restart(); // Wait for pulse while (sw.ElapsedMilliseconds < timeout && pin.Read() != value) {} if (sw.ElapsedMilliseconds >= timeout) { sw.Stop(); return 0; } sw.Restart(); // Wait for pulse end while (sw.ElapsedMilliseconds < timeout && pin.Read() == value) { } sw.Stop(); return sw.ElapsedMilliseconds < timeout ? sw.Elapsed.TotalMilliseconds : 0; }
/// <summary> /// Initialize GPIO pins /// Initialise les pin GPIO /// </summary> private void InitGpio() { var gpio = GpioController.GetDefault(); _echoPin = gpio.OpenPin(ECHO_PIN); _triggerPin = gpio.OpenPin(TRIGGER_PIN); _echoPin.SetDriveMode(GpioPinDriveMode.Input); _triggerPin.SetDriveMode(GpioPinDriveMode.Output); _triggerPin.Write(GpioPinValue.Low); var value = _triggerPin.Read(); }
private void KEYoneDown(GpioPin gpioPin, GpioPinValueChangedEventArgs e) { if (gpioPin.Read() == GpioPinValue.Low) { Debug.WriteLine("LED ON"); pinLed.Write(GpioPinValue.High); DistanceReading(); } else { pinLed.Write(GpioPinValue.Low); } }
private void VoiceDete(GpioPin gpioPin, GpioPinValueChangedEventArgs e) { if (gpioPin.Read() == GpioPinValue.Low) { Debug.WriteLine("VoiceDete"); DistanceReading(); } }
private double PulseIn(GpioPin pin, GpioPinValue value, ushort timeout) { var sw = new Stopwatch(); var sw_timeout = new Stopwatch(); sw_timeout.Start(); // Wait for pulse while (pin.Read() != value) { if (sw_timeout.ElapsedMilliseconds > timeout) return 3.5; } sw.Start(); // Wait for pulse end while (pin.Read() == value) { if (sw_timeout.ElapsedMilliseconds > timeout) return 3.4; } sw.Stop(); return sw.Elapsed.TotalSeconds; }
private void valueChanged(GpioPin sender, GpioPinValueChangedEventArgs args) { var t = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { if (sender.Read().ToString().ToLower() == "low") { uiGpioMap["GPIO_" + sender.PinNumber].Foreground = new SolidColorBrush(Colors.Red); } else { uiGpioMap["GPIO_" + sender.PinNumber].Foreground = new SolidColorBrush(Colors.Green); } uiGpioMap["GPIO_" + sender.PinNumber].Text = sender.Read().ToString(); }); }
/* /// <summary> /// LeftIRLine reads the current value /// of the left IR line sensor /// </summary> public static bool LeftIRLine() { GpioPinValue pinVal = flIRLinePin.Read(); if (pinVal == 0) { return true; } else { return false; } } // end LeftIRLine /// <summary> /// RightIRLine reads the current value /// of the right IR line sensor /// </summary> public static bool RightIRLine() { GpioPinValue pinVal = frIRLinePin.Read(); if (pinVal == 0) { return true; } else { return false; } } // end RightIRLine */ //*******************************// //*** SETUP ULTRASONIC SENSOR ***// //*******************************// /// <summary> /// getElapsedTime uses the ultrasonic sensor to /// send out a pulse and records the time it /// takes to be read back in by the sensor /// </summary> public static decimal GetElapsedTime() { decimal start = 0.00m; decimal stop = 0.00m; Stopwatch count = new Stopwatch(); long seed = Environment.TickCount; sonarPin = gpioController.OpenPin(SONAR_PIN); sonarPin.SetDriveMode(GpioPinDriveMode.Output); sonarPin.Write(GpioPinValue.Low); new System.Threading.ManualResetEvent(false).WaitOne(10); // pause thread for 10 microseconds sonarPin.Write(GpioPinValue.High); count.Start(); sonarPin.SetDriveMode(GpioPinDriveMode.Input); GpioPinValue sonarVal = sonarPin.Read(); while (sonarVal == 0 && count.ElapsedMilliseconds < 100) { start = DateTime.Now.Ticks / (decimal)TimeSpan.TicksPerMillisecond; sonarVal = sonarPin.Read(); // update sonarVal } count.Restart(); while (sonarVal != 0 && count.ElapsedMilliseconds < 100) { stop = DateTime.Now.Ticks / (decimal)TimeSpan.TicksPerMillisecond; sonarVal = sonarPin.Read(); // update sonarVal } decimal elapsedTime = stop - start; decimal etSec = elapsedTime * 0.001m; // convert elapsedTime from milliseconds to seconds return etSec; /* IMPLEMENTATION NOTE: * To get a distance value, multiply the return value (etSec) * by the time it takes the signal to reach a target and return * (e.g. etSec * 34000 = cm/s). Then divide that value by * two to get the distance between the bot and a particular object */ }
private void StartMonitoring() { this.txtOutput.Text = string.Empty; this.txtOutput.Text = DateTime.Now.Ticks.ToString() + "\n"; var gpio = GpioController.GetDefault(); //setPin = gpio.OpenPin(SET_PIN); _clockPin = gpio.OpenPin(CLOCK_PIN); _dataPin = gpio.OpenPin(DATA_PIN); //_clockPin.SetDriveMode(GpioPinDriveMode.Output); //_dataPin.SetDriveMode(GpioPinDriveMode.Input); //byte data[3]; //// pulse the clock pin 24 times to read the data //for (byte j = 3; j--;) //{ // for (char i = 8; i--;) // { // digitalWrite(PD_SCK, HIGH); // bitWrite(data[j], i, digitalRead(DOUT)); // digitalWrite(PD_SCK, LOW); //} //for (byte j = 3; j <= 0; j--) { // this.txtOutput.Text += "j " + j.ToString() + "\n"; //} var c = 0; for (int j = 2; j >= 0; j--) { this.txtOutput.Text += "Byte:" + j + "\n"; for (int i = 7; i >= 0; i--) { _clockPin.Write(GpioPinValue.High); var dataPinValue = _dataPin.Read(); _clockPin.Write(GpioPinValue.Low); if (dataPinValue == GpioPinValue.Low) { var yay = true; } this.txtOutput.Text += dataPinValue + "\n"; c++; } } // Release the GPIO pins. if (_dataPin != null) { _dataPin.Dispose(); _dataPin = null; } if (_clockPin != null) { _clockPin.Dispose(); _clockPin = null; } }
public async void InitGpio() { gpioController = GpioController.GetDefault(); try { switchPin1 = gpioController.OpenPin(switchPinNum1); switchPin2 = gpioController.OpenPin(switchPinNum2); switchPin1.SetDriveMode(GpioPinDriveMode.Input); switchPin2.SetDriveMode(GpioPinDriveMode.Input); GpioPinValue v1 = switchPin1.Read(); GpioPinValue v2 = switchPin2.Read(); ////Set Initial //if (switchPin1.Read() == GpioPinValue.Low) //{ // selectedLang = en_lang; // //selectedLang = ch_lang; //} //else //{ // selectedLang = ch_lang; //} // selectLang(); await startSRProcess(); switchPin1.DebounceTimeout = new TimeSpan(0, 0, 0, 1, 0); // value change switchPin1.ValueChanged += async (s, e) => { if (isListening) { try { await speechRecognizer.ContinuousRecognitionSession.StopAsync(); } catch { } } // await selectLang(); await startSRProcess(); }; } catch (Exception ex) { } }
private void Switch_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args) { if (args.Edge == GpioPinEdge.RisingEdge) //When a switch is pressed { UpdateSwitchLayoutColor(map[sender], sender.Read()); //Update the GUI with the new status } }
/// <summary> /// Mimic the PulseIn Arduino command. Returns, in ms, the pulse duration time. /// Mimique la commande Arduino PulseIn. Retourne, en ms, la durée de l'impulsion. /// </summary> /// <param name="pin">The pin to read / Le pin a lire</param> /// <param name="value">The pulse value / La valeur de l'impulsion</param> /// <returns>Pulse duration in ms / Durée de l'impulsion en ms</returns> private double PulseIn(GpioPin pin, GpioPinValue value) { var sw = new Stopwatch(); // Wait for pulse // Attend l'impulsion while (pin.Read() != value) { } sw.Start(); // Wait for pulse end // Attend la fin de l'impulsion while (pin.Read() == value) { } sw.Stop(); return sw.Elapsed.TotalSeconds; }
/// <summary> /// Returns the duration of a pulse in seconds, or <c>null</c> if a timeout occurred. /// </summary> /// <param name="pin">The pin on which you want to read the pulse.</param> /// <param name="value">The type of the pulse to read.</param> /// <param name="timeoutInSeconds">The number of seconds to wait before timeout.</param> /// <returns>The duration of the pulse in seconds or <c>null</c> if no pulse is completed before the timeout.</returns> /// <remarks> /// This method is similar to Arduino's pulseIn() function, except that it returns <c>null</c> in case of timeout, not zero. /// </remarks> private static double? PulseIn( GpioPin pin, GpioPinValue value, int timeoutInSeconds = 1 ) { Stopwatch pulseStopwatch = new Stopwatch(); Stopwatch timeoutStopwatch = new Stopwatch(); timeoutStopwatch.Start(); // Wait for pulse start. while( pin.Read() != value ) { if( timeoutStopwatch.Elapsed.TotalSeconds > timeoutInSeconds ) { timeoutStopwatch.Stop(); return null; } } pulseStopwatch.Start(); // Wait for pulse end. while( pin.Read() == value ) { } pulseStopwatch.Stop(); return pulseStopwatch.Elapsed.TotalSeconds; }