Guide to Getting Started
Now let's connect the LEDs to the hardware devices that have WINDOWS10 IoT Core installed and create an application to make them blink.
Load a project in Visual Studio
Here we find the routines here, which are available in C + + and C # versions. This tutorial only covers versions that use C #. Copy the project folder to disk and open it in Visual Studio.
Then check your Windows IoT device and make sure the remote debugging feature is turned on (debugging), and you can refer to the Hello World program here.
Note that if Windows 10 cannot find an available Gpio interface, the application will not work. For example, you installed the WINDOWS10 in a VM virtual machine.
Connecting the LEDs to Windows 10 devices
Prepare the following things:
One LED light
One resistance 220 ohm resistor
Several DuPont lines and bread boards
Connect the negative pole of the led to the Gpio 5 pin of the Raspberry Pi2 (Board number 29), and the positive series is connected to the 3.3v power supply. (Be sure to pay attention to polarity, in the LED in the inline package, the longer pin is the positive +, the shorter pin is the negative-)
deploying applications
For Raspberry Pi2, you should select arm from the Architecture drop-down menu.
The above steps are done later. You can press F5, the program will run automatically, then you can see the flashing LEDs and the following analog interface.
The active time of the LED blink can be adjusted by changing the position of the slider.
Code explanation
Here is the code of this program, the basic principle is that when the timer time is reached, the call event tick changes the status of the LED.
Timer code
Here is the C # code to set the timer
Public MainPage () { //... This.timer = new DispatcherTimer (); This.timer.Interval = Timespan.frommilliseconds (+); This.timer.Tick + = Timer_tick; This.timer.Start (); // ...} private void Timer_tick (object sender, Object e) { flipled ();}
Initializing the Gpio Pin
In order to be able to drive a gpio, first it needs to be initialized, here is the C # code of the Initialization program
Using windows.devices.gpio;private void Initgpio () { var Gpio = Gpiocontroller.getdefault (); Show An error if there is no Gpio controller if (GPIO = = null) { pin = null; Gpiostatus.text = "There is no GPIO controller on this device."; return; } Pin = Gpio. Openpin (Led_pin); Show an error if the pin wasn ' t initialized properly if (pin = = null) { Gpiostatus.text = "There were PR Oblems initializing the GPIO pin. "; return; } Pin. Write (Gpiopinvalue.high); Pin. Setdrivemode (gpiopindrivemode.output); Gpiostatus.text = "GPIO pin initialized correctly.";}
The simple explanation is:
~ First, use Gpiocontroller.getdefault () to get Gpio control permissions
~ returns NULL if the device does not have a GPIO resource available
~ Next turn on the Gpio pin by calling the Gpiocontroller.openpin () function
~ When we obtain the control of the Gpio and turn on the GPIO pin, use the Gpiopin.write () function to turn the LED off (parameter set high)
~ the Gpiopin.setdrivemode () function is also used to set the operating mode of the GPIO pin to output mode.
Changing the status of the Gpio Pin
Turn on the LEDs using the Gpiopinvalue.low parameter:
This.pin.Write (Gpiopinvalue.low);
To turn off the LEDs using the Gpiopinvalue.high parameter:
This.pin.Write (Gpiopinvalue.high);
Because we connect the LEDs to the 3.3V power supply, the LEDs are turned on by placing the Gpio pin low.
This article comes from: Raspberry Pi Lab
Link Address: http://shumeipai.nxez.com/2015/05/01/raspberrypi-develop-win10-samples-blinky.html
Raspberry Pi Windows10 IoT Core development Tutorial