/// <summary>
        /// 
        /// </summary>
        private void InitGpio()
        {
            var gpio = GpioController.GetDefault();
            if (gpio== null)
            {
                Debug.WriteLine("Can't find GpioController.");
                return;
            }

            pin = gpio.OpenPin(inputPin);

            if (pin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                pin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                pin.SetDriveMode(GpioPinDriveMode.Input);
            }

            Debug.WriteLine("GPIO initializing...");

            //Sleep
            for (int i = 0; i <= 10000; i++) { }

            //Event
            pin.ValueChanged += Pin_ValueChanged;

            Debug.WriteLine("GPIO initialized.");
        }
Example #2
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            if (gpio == null)
            {
                GpioStatus.Text = "There is no GPIO controller on this device.";
                return;
            }

            button1Pin = gpio.OpenPin(BUTTON1_PIN);
            led1Pin = gpio.OpenPin(LED1_PIN);

            // Initialize LED to the OFF state by first writing a HIGH value
            led1Pin.Write(GpioPinValue.High);
            led1Pin.SetDriveMode(GpioPinDriveMode.Output);

            // Check if input pull-up resistors are supported
            if (button1Pin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                button1Pin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            else
                button1Pin.SetDriveMode(GpioPinDriveMode.Input);

            // Set a debounce timeout to filter out switch bounce noise from a button press
            button1Pin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            // Register for the ValueChanged event so our buttonPin_ValueChanged 
            // function is called when the button is pressed
            button1Pin.ValueChanged += buttonPin_ValueChanged;

            GpioStatus.Text = "GPIO pins initialized correctly.";
        }
Example #3
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            // error prompt
            if (gpio == null) {
                GpioStatus.Text = "There's no GPIO controller on this device";
                return -1;
            }

            buttonPin = gpio.OpenPin(BUTTON_PIN);
            ledPin = gpio.OpenPin(LED_PIN);

            // init LED to OFF by HIGH, cuz LED is wired in LOW config
            ledPin.Write(GpioPinValue.High);
            ledPin.SetDriveMode(GpioPinDriveMode.Output);

            // checking if input pull-up resistors are supported
            if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp)) {
                buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else {
                buttonPin.SetDriveMode(GpioPinDriveMode.Input);
            }

            // setting debounce timeout
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            // register for ValueChanged event
            // so buttonPin_ValueChanged()
            // is called when button is pressed
            buttonPin.ValueChanged += buttonPin_ValueChanged;

            GpioStatus.Text = "GPIO pins initialized correctly";
        }
Example #4
0
        public override void Init()
        {
            Debug.WriteLine("Initializing push button.");

            try
            {
                _pushButtonPin = _gpioController.OpenPin(Pin);

                if (_pushButtonPin == null)
                {
                    Debug.WriteLine(string.Format("Push button pin not found at GPIO {0}.", Pin));
                    throw new Exception(string.Format("Push button pin not found at GPIO {0}.", Pin));
                }
                else
                {
                    Debug.WriteLine(string.Format("Push button initialized at GPIO {0}.", Pin));
                }

                if (_pushButtonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                    _pushButtonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
                else
                    _pushButtonPin.SetDriveMode(GpioPinDriveMode.Input);

                _pushButtonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

                _pushButtonPin.ValueChanged += _pushButtonPin_ValueChanged;

                Debug.WriteLine("Push button initialized.");
            }
            catch
            {
                Debug.WriteLine("Failed to initialize push button.");
                throw new Exception("Failed to initialize push button.");
            }
        }
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                _buttonpin = null;
                _buzzerpin = null;
                GpioStatus.Text = "There is no GPIO controller on this device.";
                return;
            }

            _buttonpin = gpio.OpenPin(BUTTON_PIN);
            _buzzerpin = gpio.OpenPin(BUZZER_PIN);

            if (_buttonpin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                _buttonpin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            else
                _buttonpin.SetDriveMode(GpioPinDriveMode.Input);

            _buttonpin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            _buttonpin.ValueChanged += Buttonpin_ValueChanged;

            _buzzerpin.Write(GpioPinValue.Low);
            _buzzerpin.SetDriveMode(GpioPinDriveMode.Output);

            GpioStatus.Text = "GPIO button and buzzer pin initialized correctly.";
        }
Example #6
0
File: Dht11.cs Project: BeRoces/iot
        public void Init(GpioPin gpioPin)
        {
            // Use InputPullUp if supported, otherwise fall back to Input (floating)
            inputDriveMode =
                gpioPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp) ?
                GpioPinDriveMode.InputPullUp : GpioPinDriveMode.Input;

            gpioPin.SetDriveMode(inputDriveMode);
            pin = gpioPin;
        }
Example #7
0
        void _init()
        {
            _pin = _gpio.OpenPin(_pinNumber, _sharingMode);

            if (!_pin.IsDriveModeSupported(_driveMode))
            {
                throw new NotSupportedException($"Drive mode {_driveMode} not supported on pin {_pinNumber}");    
            }

            _pin.SetDriveMode(_driveMode);
        }
        /// <summary>
        /// Attempts to initialize Gpio for application. This includes doorbell interaction and locking/unlccking of door.
        /// Returns true if initialization is successful and Gpio can be utilized. Returns false otherwise.
        /// </summary>
        public bool Initialize()
        {
            // Gets the GpioController
            gpioController = GpioController.GetDefault();
            if(gpioController == null)
            {
                // There is no Gpio Controller on this device, return false.
                return false;
            }

            // Opens the GPIO pin that interacts with the doorbel button
            doorbellPin = gpioController.OpenPin(GpioConstants.ButtonPinID);

            if (doorbellPin == null)
            {
                // Pin wasn't opened properly, return false
                return false;
            }

            // Set a debounce timeout to filter out switch bounce noise from a button press
            doorbellPin.DebounceTimeout = TimeSpan.FromMilliseconds(25);

            if (doorbellPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                // Take advantage of built in pull-up resistors of Raspberry Pi 2 and DragonBoard 410c
                doorbellPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                // MBM does not support PullUp as it does not have built in pull-up resistors 
                doorbellPin.SetDriveMode(GpioPinDriveMode.Input);
            }

            // Opens the GPIO pin that interacts with the door lock system
            doorLockPin = gpioController.OpenPin(GpioConstants.DoorLockPinID);
            if(doorLockPin == null)
            {
                // Pin wasn't opened properly, return false
                return false;
            }
            // Sets doorbell pin drive mode to output as pin will be used to output information to lock
            doorLockPin.SetDriveMode(GpioPinDriveMode.Output);
            // Initializes pin to high voltage. This locks the door. 
            doorLockPin.Write(GpioPinValue.High);

            //Initialization was successfull, return true
            return true;
        }
        private void InitGPIO()
        {
            // Initialize the GPIO controller
            GpioController gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                _pin1 = null;
                _pin2 = null;
                _pin3 = null;
                GpioStatus.Text = "There is no GPIO controller on this device.";
                return;
            }

            // Initialize the GPIO pin for the first LED
            _pin1 = gpio.OpenPin(LED1_PIN);
            _pin1.SetDriveMode(GpioPinDriveMode.Output);
            _pin1.Write(GpioPinValue.High);

            // Initialize the GPIO pin for the second LED
            _pin2 = gpio.OpenPin(LED2_PIN);
            _pin2.SetDriveMode(GpioPinDriveMode.Output);
            _pin2.Write(GpioPinValue.Low);

            // Initialize the LED1 Ellipse to draw Gray
            LED1.Fill = _redBrush;

            // Initialize Button pin
            _pin3 = gpio.OpenPin(BUTT_PIN);

            // Check if input pull-up resistors are supported
            if (_pin3.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                _pin3.SetDriveMode(GpioPinDriveMode.InputPullUp);
            else
                _pin3.SetDriveMode(GpioPinDriveMode.Input);
            
            // Set a debounce timeout to filter out switch bounce noise from a button press
            _pin3.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            
            // Register for the ValueChanged event so our buttonPin_ValueChanged 
            // function is called when the button is pressed
            _pin3.ValueChanged += _pin3_ValueChanged;

            // Show the GPIO is OK message
            GpioStatus.Text = "GPIO pin initialized correctly.";
        }
        public MainPage()
        {
            this.InitializeComponent();
            //GPIO();
            //InitDancing();

            stopwatch = Stopwatch.StartNew();

            GpioController gpio = GpioController.GetDefault();
            buttonPin = gpio.OpenPin(21);
            if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            else
                buttonPin.SetDriveMode(GpioPinDriveMode.Input);
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            buttonPin2 = gpio.OpenPin(20);
            if (buttonPin2.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                buttonPin2.SetDriveMode(GpioPinDriveMode.InputPullUp);
            else
                buttonPin2.SetDriveMode(GpioPinDriveMode.Input);
            buttonPin2.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(BEAT_PACE);
            timer.Tick += Beat;
            
            servoPinA = gpio.OpenPin(SERVO_PIN_A);
            servoPinA.SetDriveMode(GpioPinDriveMode.Output);
            buttonPin.ValueChanged += Pin1_ValueChanged;
            buttonPin2.ValueChanged += ButtonPin2_ValueChanged;

            force();
            //AsyncFunc();

            //WebSocket();
        }
Example #11
0
        private void InitGPIO()
        {
            // Instantiate the Azure device client
            deviceClient = DeviceClient.CreateFromConnectionString(IOT_HUB_CONN_STRING);

            var gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                GpioStatus.Text = "There is no GPIO controller on this device.";
                return;
            }

            buttonPin = gpio.OpenPin(BUTTON_PIN);
            ledPin = gpio.OpenPin(LED_PIN);

            // Initialize LED to the OFF state by first writing a HIGH value
            // We write HIGH because the LED is wired in a active LOW configuration
            ledPin.Write(GpioPinValue.High);
            ledPin.SetDriveMode(GpioPinDriveMode.Output);

            // Check if input pull-up resistors are supported
            if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            else
                buttonPin.SetDriveMode(GpioPinDriveMode.Input);

            // Set a debounce timeout to filter out switch bounce noise from a button press
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(5);

            // Register for the ValueChanged event so our buttonPin_ValueChanged 
            // function is called when the button is pressed
            buttonPin.ValueChanged += buttonPin_ValueChanged;

            GpioStatus.Text = "GPIO pins initialized correctly.";
        }
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                _buttonpin = null;
                GpioStatus.Text = "There is no GPIO controller on this device.";
                return;
            }

            _buttonpin = gpio.OpenPin(BUTTON_PIN);

            if (_buttonpin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                _buttonpin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            else
                _buttonpin.SetDriveMode(GpioPinDriveMode.Input);

            _buttonpin.DebounceTimeout = TimeSpan.FromMilliseconds(50); // Delay time the ValueChanged event is fired after pressing or releasing the button
            _buttonpin.ValueChanged += Buttonpin_ValueChanged;

            GpioStatus.Text = "GPIO button pin initialized correctly.";
        }
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                return;
            }

            _doorUpPin = gpio.OpenPin(DOOR_UP_PIN);
            _doorDownPin = gpio.OpenPin(DOOR_DOWN_PIN);

            if (_doorUpPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                _doorUpPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            else
                _doorUpPin.SetDriveMode(GpioPinDriveMode.Input);
            _doorUpPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            _doorUpPin.ValueChanged += _doorUpPin_ValueChanged;

            if (_doorDownPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                _doorDownPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            else
                _doorDownPin.SetDriveMode(GpioPinDriveMode.Input);
            _doorDownPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            _doorDownPin.ValueChanged += _doorDownPin_ValueChanged;

            _doorRelayPin = gpio.OpenPin(DOOR_RELAY_PIN);
            _doorRelayPin.Write(GpioPinValue.High);
            _doorRelayPin.SetDriveMode(GpioPinDriveMode.Output);
        }
Example #14
0
        private void InitHeartRateSensor()
        {
            m_heart_rate_sensor = m_gpio.OpenPin(HEART_RATE_SENSOR_PIN);


            if (m_heart_rate_sensor.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                //change this if you get rid of the external pull up
                m_heart_rate_sensor.SetDriveMode(GpioPinDriveMode.Input);
            }
            else
            {
                m_heart_rate_sensor.SetDriveMode(GpioPinDriveMode.Input);
            }

            m_heart_rate_sensor.DebounceTimeout = TimeSpan.FromMilliseconds(0);
            m_heart_rate_sensor.ValueChanged += M_heart_rate_sensor_ValueChanged;

        }
Example #15
0
    /// <summary>
    /// Initializes the GpioController on the board if it exists, and initializes the Led and Button pins.
    /// </summary>
    private void InitGpio()
    {
      //Attempt to get the GpioController instance for the 
      //device.  
      var gpio = GpioController.GetDefault();

      // If no GpioController was found (gpio==null), null out the pins
      // And throw an exception indicating there was no GPIO controller
      if (gpio == null)
      {
        ledPin = null;
        buttonPin = null;
        throw new Exception("There is no GPIO controller on this device.");
      }

      //Init LED pin
      ledPin = gpio.OpenPin(LED_PIN);
      ledPin.SetDriveMode(GpioPinDriveMode.Output);
      SetLedState(false);

      //Init Button pin
      buttonPin = gpio.OpenPin(BUTTON_PIN);

      //Remember Windows 10 IoT Core runs on multiple boards.
      //If the board's pin that the button is connected to supports
      //pullup resistors, enable the pullup resistor, otherwise, just use
      //it as a normal input
      if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
      {
        buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
      }
      else
      {
        buttonPin.SetDriveMode(GpioPinDriveMode.Input);
      }

      //Set a debounce timeout to filter out switch bounce noice from a button press
      buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

      //Wire up an event hander to be called whenever the button gets pressed.
      buttonPin.ValueChanged += ButtonPin_ValueChanged;
    }
Example #16
0
        private void InitCadenceSensor()
        {
            m_cadence_sensor = m_gpio.OpenPin(CADENCE_SENSOR_PIN);


            if (m_cadence_sensor.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            { 
                
                m_cadence_sensor.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                m_cadence_sensor.SetDriveMode(GpioPinDriveMode.Input);
            }

            m_cadence_sensor.DebounceTimeout = TimeSpan.FromMilliseconds(10);
            m_cadence_sensor.ValueChanged += M_cadence_sensor_ValueChanged;

            RPM = 0;


        }
 private void initPanicButton()
 {
     var controller = GpioController.GetDefault();
     if (controller != null)
     {
         buttonPin = controller.OpenPin(4);
         if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
             buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
         else
             buttonPin.SetDriveMode(GpioPinDriveMode.Input);
         buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
         buttonPin.ValueChanged += buttonValueChanged;
     }
     else
     {
         Log("GpioController not present, cannot configure button.");
     }
 }
        private void setUpBoardIO()
        {
            //The OutPutHeartBeatPin will be set to high.  When the isolation relay
            //on the machine closes our OutPutHearBeatPin will send 5v to the hearBeatPin


            var gpioController = GpioController.GetDefault();

            if (gpioController == null)
            {
                Utilities.SparkEmail.Send(configuration.AssetNumber + " NO GPIO CONTROLLER.");
                return;
            }


            heartBeatPin = gpioController.OpenPin(HEARTBEAT_PIN);

            // Check if input pull-up resistors are supported
            if (heartBeatPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                heartBeatPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            else
                heartBeatPin.SetDriveMode(GpioPinDriveMode.Input);

            // Set a debounce timeout to filter out switch bounce noise from a button press
            heartBeatPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            heartBeatPin.ValueChanged += HeartBeatPin_ValueChanged;



        }
Example #19
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                ledPin = null;
                buttonPin = null;
                return;
            }

            ledPin = gpio.OpenPin(LED_PIN);
            buttonPin = gpio.OpenPin(BUTTON_PIN);

            // Initialize LED to the OFF state by first writing a HIGH value
            // We write HIGH because the LED is wired in a active LOW configuration
            ledPinValue = GpioPinValue.High;
            ledPin.Write(ledPinValue);
            ledPin.SetDriveMode(GpioPinDriveMode.Output);

            // Check if input pull-up resistors are supported
            if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                buttonPin.SetDriveMode(GpioPinDriveMode.Input);
            }

            // Set a debounce timeout to filter out switch bounce noise from a button press
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            // Register for the ValueChanged event so our buttonPin_ValueChanged
            // function is called when the button is pressed
            buttonPin.ValueChanged += buttonPin_ValueChanged;
        }
Example #20
0
 private void InitPirsensorPin()
 {
     MediaElement mediaElement = new MediaElement();
     SpeechSynthesizer speech = new SpeechSynthesizer();
     if (gpio == null)
         return;
     pirPin = gpio.OpenPin(5);
     if (pirPin.IsDriveModeSupported(GpioPinDriveMode.InputPullDown))
         pirPin.SetDriveMode(GpioPinDriveMode.InputPullDown);
     else
         pirPin.SetDriveMode(GpioPinDriveMode.Input);
     pirPin.SetDriveMode(GpioPinDriveMode.Input);
     pirPin.ValueChanged += (GpioPin p, GpioPinValueChangedEventArgs args) =>
     {
         if (args.Edge == GpioPinEdge.RisingEdge)
         {
             var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => {
                 IoTHelper.SendReading(DateTime.Now);
                 var msg = messages.OrderBy(x => Guid.NewGuid()).Take(1).First();
                 PirStatus.Text = msg;
                 SpeechSynthesisStream stream = await speech.SynthesizeTextToStreamAsync(msg);
                 mediaElement.SetSource(stream, stream.ContentType);
                 mediaElement.Play();
             });
         }
     };
 }
Example #21
0
        private void InitGPIO()
        {
            GpioController gpio;
            try
            {
                gpio = GpioController.GetDefault();
            }
            catch (Exception)
            {
                GpioStatus.Text = "There is no GPIO controller on this device.";
                return;
            }

            // setup the button and it's pins
            buttonPin = gpio.OpenPin(BUTTON_PIN);
            ledButtonPin = gpio.OpenPin(LED_BUTTON_PIN);

            ledButtonPin.Write(GpioPinValue.High);
            ledButtonPin.SetDriveMode(GpioPinDriveMode.Output);

            if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            else
                buttonPin.SetDriveMode(GpioPinDriveMode.Input);

            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            buttonPin.ValueChanged += buttonPin_ValueChanged;

            // setup blinking led
            ledBlinkPin = gpio.OpenPin(LED_BLINK_PIN);

            ledBlinkPin.Write(GpioPinValue.High);
            ledBlinkPin.SetDriveMode(GpioPinDriveMode.Output);

            ButtonStatus.Text = "Released";

            GpioStatus.Text = "GPIO pins initialized correctly.";
        }
Example #22
0
        private void InitAbortButton()
        {
            if (gpio == null)
                return;
            abortPin = gpio.OpenPin(13);
            ledAbortPin = gpio.OpenPin(26);
            ledAbortPin.Write(GpioPinValue.High);
            ledAbortPin.SetDriveMode(GpioPinDriveMode.Output);
            if (abortPin.IsDriveModeSupported(GpioPinDriveMode.InputPullDown))
                abortPin.SetDriveMode(GpioPinDriveMode.InputPullDown);
            else
                abortPin.SetDriveMode(GpioPinDriveMode.Input);
            abortPin.DebounceTimeout = TimeSpan.FromMilliseconds(100);
            abortPin.ValueChanged += AbortPin_ValueChanged;

            //this.abortTimer = new DispatcherTimer();
            //this.abortTimer.Interval = TimeSpan.FromTicks(trut);
            //this.abortTimer.Tick += AbortTimer_Tick;
            //this.abortTimer.Start();
        }
Example #23
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();            
            buttonPin = gpio.OpenPin(BUTTON_PIN);
            ledPin = gpio.OpenPin(LED_PIN);

            // Check if input pull-up resistors are supported
            if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            else
                buttonPin.SetDriveMode(GpioPinDriveMode.Input);

            // Set a debounce timeout to filter out switch bounce noise from a button press
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            // Register for the ValueChanged event so our buttonPin_ValueChanged 
            // function is called when the button is pressed
            buttonPin.ValueChanged += buttonPin_ValueChanged;
        }