Beispiel #1
0
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            var controller = GpioController.GetDefault();

            if (null != controller)
            {
                LedPin = controller.OpenPin(5);
                LedPin.SetDriveMode(GpioPinDriveMode.Output);
                LedPin.Write(GpioPinValue.Low); // set light to off at start up

                SoundPin = controller.OpenPin(6);
                SoundPin.SetDriveMode(GpioPinDriveMode.Input);

                SoundPin.ValueChanged += (pin, args) =>
                {
                    var pinValue = SoundPin.Read();
                    if (pinValue == GpioPinValue.Low)
                    {
                        Debug.WriteLine("Sound Detected!");
                        LedPin.Write(IsLightOn ? GpioPinValue.Low : GpioPinValue.High);
                        IsLightOn = !IsLightOn;
                    }
                };
            }
        }
 public MainViewModel()
 {
     DeviceClient   = DeviceClient.Create(IotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey(DeviceId, DeviceKey));
     GpioController = GpioController.GetDefault();
     if (null != GpioController)
     {
         LedPin = GpioController.OpenPin(4);
         LedPin.SetDriveMode(GpioPinDriveMode.Output);
     }
 }
Beispiel #3
0
        public MainPage()
        {
            this.InitializeComponent();

            GpioController = GpioController.GetDefault();

            BuzzPin = GpioController.OpenPin(5);
            BuzzPin.SetDriveMode(GpioPinDriveMode.Output);
            BuzzPin.Write(GpioPinValue.High);

            LedPin = GpioController.OpenPin(6);
            LedPin.SetDriveMode(GpioPinDriveMode.Output);
            LedPin.Write(GpioPinValue.High);
        }
        public MainPage()
        {
            this.InitializeComponent();

            GpioController = GpioController.GetDefault();
            if (null != GpioController)
            {
                ReedPin = GpioController.OpenPin(5);
                ReedPin.SetDriveMode(GpioPinDriveMode.Input);
                ReedPin.ValueChanged += (sender, args) =>
                {
                    if (ReedPin.Read() == GpioPinValue.Low)
                    {
                        IsLightOn = !IsLightOn;

                        LedPin.Write(IsLightOn ? GpioPinValue.Low : GpioPinValue.High);
                    }
                };

                LedPin = GpioController.OpenPin(6);
                LedPin.SetDriveMode(GpioPinDriveMode.Output);
                LedPin.Write(GpioPinValue.High);
            }
        }
Beispiel #5
0
 private void InitializeLed(GpioController controller)
 {
     LedPin = controller.OpenPin(LedPinNumber);
     LedPin.SetDriveMode(GpioPinDriveMode.Output);
     LedPin.Write(IsOn ? GpioPinValue.High : GpioPinValue.Low);
 }