Friday, August 12, 2016

Windows IOT - Blink Dual Diode

After checking out the blinky app with Windows IOT on Raspberry Pi3.

so lets make a simple dual blinky app.

Extended hardware needed from the original Blinky is another diode and resistance or dual diode.

In my simple setup I used the dual diode that came with the È37 sensor kit from SunFlowerÈ.

Connection configuration as below:

Dual Diode
-GRD-              -------------- Connected to Ground through one resistance (220 ohm)
  -G-                  -------------- Connected to Pin 5
  -R-                   -------------- Connected to Pin 6

Application as follow:
the main console class have the following private members
        private GpioPin pin5;
        private GpioPin pin6;
        private DispatcherTimer timer;

  public MainPage()
        {
            InitializeComponent();
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(500);
            timer.Tick += Timer_Tick;
            InitGPIO();
            if (pin5 != null)
            {
                timer.Start();
            }      
        } 

 private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();
            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                pin5 = null;
                pin6 = null;
                GpioStatus.Text = "There is no GPIO controller on this device.";
                return;
            }
            pin5 = gpio.OpenPin(5);
            pin6 = gpio.OpenPin(6);
            pin5.SetDriveMode(GpioPinDriveMode.Output);
            pin6.SetDriveMode(GpioPinDriveMode.Output);
            GpioStatus.Text = "GPIO pin initialized correctly.";
        } 


        private int index = 0;
        private void Timer_Tick(object sender, object e)
        {
            index++;
            if (index > 3) index = 0;
            switch (index)
            {
                case 0:
                    pin5.Write(GpioPinValue.Low);
                    pin6.Write(GpioPinValue.Low);
                    break;
                case 1:
                    pin5.Write(GpioPinValue.High);
                    pin6.Write(GpioPinValue.Low);
                    break;
                case 2:
                    pin5.Write(GpioPinValue.High);
                    pin6.Write(GpioPinValue.High);
                    break;
                case 3:
                    pin5.Write(GpioPinValue.Low);
                    pin6.Write(GpioPinValue.High);
                    break;
            }
        }
the result as below:-


No comments:

Post a Comment