Esempio n. 1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // ***
            // *** Get a reference to the GPIO Controller.
            // ***
            GpioController controller = GpioController.GetDefault();

            // ***
            // *** Make sure the reference is valid (that e are connected to a device with
            // *** a GPIO Controller.
            // ***
            if (controller != null)
            {
                // ***
                // *** Set up the data pin.
                // ***
                GpioPin dataPin = GpioController.GetDefault().OpenPin(5, GpioSharingMode.Exclusive);
                dataPin.SetDriveMode(GpioPinDriveMode.Input);

                // ***
                // *** Set up the trigger pin.
                // ***
                GpioPin triggerPin = GpioController.GetDefault().OpenPin(4, GpioSharingMode.Exclusive);
                triggerPin.SetDriveMode(GpioPinDriveMode.Output);

                // ***
                // *** Create the sensor.
                // ***
                _sensor = new Dht22(dataPin, triggerPin);
                await _sensor.Initialize();
            }

            // ***
            // *** Start the timer.
            // ***
            _timer.Start();
        }