Ejemplo n.º 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;
                    }
                };
            }
        }
Ejemplo n.º 2
0
        public async Task ReceiveCloudToDeviceMessageAsync()
        {
            CloudToDeviceLog = "Receiving events...";
            Debug.WriteLine("\nReceiving cloud to device messages from service");

            while (true)
            {
                Message receivedMessage = await DeviceClient.ReceiveAsync();

                if (receivedMessage == null)
                {
                    continue;
                }

                var msg = Encoding.ASCII.GetString(receivedMessage.GetBytes());
                CloudToDeviceLog += "\nReceived message: " + msg;

                if (msg == "on")
                {
                    LedPin.Write(GpioPinValue.Low);
                }

                if (msg == "off")
                {
                    LedPin.Write(GpioPinValue.High);
                }

                await DeviceClient.CompleteAsync(receivedMessage);
            }
        }
Ejemplo n.º 3
0
        public TreatDispenser(GpioController controller)
        {
            _ledPin    = LedPin.Initialize(controller, 18, LedPinState.Off);
            _buttonPin = ButtonPin.Initialize(controller, 23, PinMode.InputPullDown);

            _buttonPin.OnButtonUp += async(s, e) =>
            {
                await DispenseAsync().ConfigureAwait(false);
            };
        }
 public MainViewModel()
 {
     DeviceClient   = DeviceClient.Create(IotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey(DeviceId, DeviceKey));
     GpioController = GpioController.GetDefault();
     if (null != GpioController)
     {
         LedPin = GpioController.OpenPin(4);
         LedPin.SetDriveMode(GpioPinDriveMode.Output);
     }
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        private async Task MorseToBeep(string morse)
        {
            foreach (var c in morse)
            {
                switch (c)
                {
                case '.':
                    BuzzPin.Write(GpioPinValue.Low);
                    LedPin.Write(GpioPinValue.Low);
                    await Task.Delay(100);

                    BuzzPin.Write(GpioPinValue.High);
                    LedPin.Write(GpioPinValue.High);
                    break;

                case '-':
                    BuzzPin.Write(GpioPinValue.Low);
                    LedPin.Write(GpioPinValue.Low);
                    await Task.Delay(300);

                    BuzzPin.Write(GpioPinValue.High);
                    LedPin.Write(GpioPinValue.High);
                    break;

                case '/':
                    BuzzPin.Write(GpioPinValue.High);
                    LedPin.Write(GpioPinValue.High);
                    await Task.Delay(200);

                    break;

                default:
                    break;
                }

                await Task.Delay(50);
            }
        }
Ejemplo n.º 7
0
        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);
            }
        }
Ejemplo n.º 8
0
 public void TurnOff()
 {
     LedPin.Write(GpioPinValue.Low);
     IsOn = false;
 }
Ejemplo n.º 9
0
 public void TurnOn()
 {
     LedPin.Write(GpioPinValue.High);
     IsOn = true;
 }
Ejemplo n.º 10
0
 private void InitializeLed(GpioController controller)
 {
     LedPin = controller.OpenPin(LedPinNumber);
     LedPin.SetDriveMode(GpioPinDriveMode.Output);
     LedPin.Write(IsOn ? GpioPinValue.High : GpioPinValue.Low);
 }
Ejemplo n.º 11
0
 private void SetLedState(LedPin eled, bool state)
 {
     Console.WriteLine("Setting led {0} {1}", eled, state);
     gpioPinsConnection[LedToPin.TryGetOrDefault(eled)] = state;
 }
Ejemplo n.º 12
0
 private void SetLedState(LedPin eled, bool state)
 {
     Console.WriteLine("Setting led {0} {1}", eled, state);
     gpioPinsConnection[LedToPin.TryGetOrDefault(eled)] = state;
 }