private static void InitGPIO() { gpio = GpioController.GetDefault(); if (gpio == null) { irLED = null; debugString = "There is no GPIO controller on this device.\n"; return; } irReceiver = gpio.OpenPin(IR_RCV_PIN, GpioSharingMode.Exclusive); irReceiver.SetDriveMode(GpioPinDriveMode.InputPullUp); irReceiverReader = new GpioChangeReader(irReceiver); irReceiverReader.Polarity = GpioChangePolarity.Both; irLED = gpio.OpenPin(IR_LED_PIN); irLED.Write(GpioPinValue.Low); irLED.SetDriveMode(GpioPinDriveMode.Output); statusLED = gpio.OpenPin(STATUS_LED_PIN); statusLED.Write(GpioPinValue.Low); statusLED.SetDriveMode(GpioPinDriveMode.Output); button = gpio.OpenPin(BTN_PIN); button.SetDriveMode(GpioPinDriveMode.Input); debugString = "GPIO pin initialized correctly.\n"; }
public MainPage() { InitializeComponent(); try { var gpioController = GpioController.GetDefault(); _inputPin = gpioController.OpenPin(INDEX_INPUT_PIN, GpioSharingMode.Exclusive); _outputPin = gpioController.OpenPin(INDEX_OUTPUT_PIN, GpioSharingMode.Exclusive); // Use InputPullUp if supported, otherwise fall back to Input (floating) _inputDriveMode = _inputPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp) ? GpioPinDriveMode.InputPullUp : GpioPinDriveMode.Input; _inputPin.SetDriveMode(_inputDriveMode); _outputPin.Write(GpioPinValue.Low); _outputPin.SetDriveMode(GpioPinDriveMode.Output); _changeReader = new GpioChangeReader(_inputPin, 43) { Polarity = GpioChangePolarity.Falling, }; _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(INTERVAL_DATA_READING); _timer.Tick += HandleEvent_DispatcherTimer_Tick; } catch (Exception ex) { UpdateStatus(ex.Message); } }
private long minTicks = 0; // System latency, /// <summary> /// Constructor /// </summary> /// <param name="pinTrig">Netduino pin connected to the HC-SR04 Trig pin</param> /// <param name="pinEcho">Netduino pin connected to the HC-SR04 Echo pin</param> public HC_SR04(int pinTrig, int pinEcho) { portOut = GpioController.GetDefault().OpenPin(pinTrig); portOut.Write(GpioPinValue.Low); portOut.SetDriveMode(GpioPinDriveMode.Output); interIn = new GpioChangeReader(pinEcho, GpioPinDriveMode.InputPullUp);//GpioController.GetDefault().OpenPin(pinEcho);//new InterruptPort(pinEcho, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow); //interIn.OnInterrupt += new NativeEventHandler(interIn_OnInterrupt); interIn.SetDriveMode(GpioPinDriveMode.InputPullUp); interIn.ValueChanged += interIn_OnInterrupt; minTicks = 4000L; }
private async void InitGPIO() { if (LightningProvider.IsLightningEnabled) { LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider(); /* * var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider()); * var pwmController = pwmControllers[1]; // the on-device controller * pwmController.SetDesiredFrequency(40); // try to match 50Hz * * pwmLED = pwmController.OpenPin(IR_LED_PIN); * pwmLED.SetActiveDutyCyclePercentage(0); * pwmLED.Start();*/ } var gpio = GpioController.GetDefault(); if (gpio == null) { irLED = null; debugString = "There is no GPIO controller on this device.\n"; GpioStatus.Text = debugString; return; } irReceiver = gpio.OpenPin(RCV_PIN, GpioSharingMode.Exclusive); irReceiver.SetDriveMode(GpioPinDriveMode.InputPullUp); irReceiverReader = new GpioChangeReader(irReceiver); irReceiverReader.Start(); irLED = gpio.OpenPin(IR_LED_PIN); irLED.Write(GpioPinValue.Low); irLED.SetDriveMode(GpioPinDriveMode.Output); //irReceiver.ValueChanged += OnChange; debugString = "GPIO pin initialized correctly.\n"; GpioStatus.Text = debugString; flipsAmount = 0; }
/// <summary> /// Initializes the sensor. /// </summary> public async Task Initialize() { // *** // *** Set the trigger pin LOW which sets the data pin HIGH. // *** this.TriggerPin.Write(GpioPinValue.Low); // *** // *** Initialize the change reader. // *** this.ChangeReader = new GpioChangeReader(this.DataPin) { Polarity = GpioChangePolarity.Falling }; // *** // *** The data sheet states that the sensor should be given 1 second to initialize. // *** await Task.Delay(TimeSpan.FromSeconds(1)); }
private void InitGpio() { gpioController = GpioController.GetDefault(); if (gpioController == null) { return; } driverPin = gpioController.OpenPin(PIN_DRIVER); echoPin = gpioController.OpenPin(PIN_ECHO); driverPin.Write(GpioPinValue.Low); driverPin.SetDriveMode(GpioPinDriveMode.Output); echoPin.SetDriveMode(GpioPinDriveMode.InputPullDown); changeReader = new GpioChangeReader(echoPin); changeReader.Polarity = GpioChangePolarity.Both; // one measurement results in one rising and one falling edge changeReader.Start(); // we use the stopwatch to time the trigger pulse stopwatch = Stopwatch.StartNew(); stopwatch.Start(); }
private void InitGPIO() { GpioController gpioController = GpioController.GetDefault(); _triggerPin = gpioController.OpenPin(TRIGGERPIN, GpioSharingMode.Exclusive); _triggerPin.Write(GpioPinValue.Low); _triggerPin.SetDriveMode(GpioPinDriveMode.Output); _echoPin = gpioController.OpenPin(ECHOPIN, GpioSharingMode.Exclusive); _echoPin.Write(GpioPinValue.Low); _echoPin.SetDriveMode(GpioPinDriveMode.Input); _echoBackReader = new GpioChangeReader(_echoPin) { // we are looking for the width of a pulse sent from the HC-SR04 so we need the // time from the rising edge to the falling edge Polarity = GpioChangePolarity.Both }; // this is for trying pin value change interrupt method //_echoPin.ValueChanged += _echoPin_ValueChanged; }