コード例 #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;
                    }
                };
            }
        }
コード例 #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);
            }
        }
コード例 #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);
            };
        }
コード例 #4
0
 public MainViewModel()
 {
     DeviceClient   = DeviceClient.Create(IotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey(DeviceId, DeviceKey));
     GpioController = GpioController.GetDefault();
     if (null != GpioController)
     {
         LedPin = GpioController.OpenPin(4);
         LedPin.SetDriveMode(GpioPinDriveMode.Output);
     }
 }
コード例 #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);
        }
コード例 #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);
            }
        }
コード例 #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);
            }
        }
コード例 #8
0
ファイル: Led.cs プロジェクト: brentestewart/SimpleComputer
 public void TurnOff()
 {
     LedPin.Write(GpioPinValue.Low);
     IsOn = false;
 }
コード例 #9
0
ファイル: Led.cs プロジェクト: brentestewart/SimpleComputer
 public void TurnOn()
 {
     LedPin.Write(GpioPinValue.High);
     IsOn = true;
 }
コード例 #10
0
ファイル: Led.cs プロジェクト: brentestewart/SimpleComputer
 private void InitializeLed(GpioController controller)
 {
     LedPin = controller.OpenPin(LedPinNumber);
     LedPin.SetDriveMode(GpioPinDriveMode.Output);
     LedPin.Write(IsOn ? GpioPinValue.High : GpioPinValue.Low);
 }
コード例 #11
0
ファイル: Program.cs プロジェクト: yodiwo/plegma
 private void SetLedState(LedPin eled, bool state)
 {
     Console.WriteLine("Setting led {0} {1}", eled, state);
     gpioPinsConnection[LedToPin.TryGetOrDefault(eled)] = state;
 }
コード例 #12
0
 private void SetLedState(LedPin eled, bool state)
 {
     Console.WriteLine("Setting led {0} {1}", eled, state);
     gpioPinsConnection[LedToPin.TryGetOrDefault(eled)] = state;
 }