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 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);
            }
        }
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);
        }
Beispiel #4
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);
            }
        }
        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 #6
0
 public void TurnOff()
 {
     LedPin.Write(GpioPinValue.Low);
     IsOn = false;
 }
Beispiel #7
0
 public void TurnOn()
 {
     LedPin.Write(GpioPinValue.High);
     IsOn = true;
 }
Beispiel #8
0
 private void InitializeLed(GpioController controller)
 {
     LedPin = controller.OpenPin(LedPinNumber);
     LedPin.SetDriveMode(GpioPinDriveMode.Output);
     LedPin.Write(IsOn ? GpioPinValue.High : GpioPinValue.Low);
 }