Interface:
<StackPanelHorizontalAlignment= "Center"VerticalAlignment= "Center"> <TextBoxName= "InfoText"Text= "Ready"FontSize= " the"HorizontalAlignment= "Center"VerticalAlignment= "Center"></TextBox> <ButtonName= "Submitaction"FontSize= " the"HorizontalAlignment= "Center"VerticalAlignment= "Center"Click= "Submitaction_click">Exit</Button> </StackPanel>
Code:
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Runtime.InteropServices.WindowsRuntime;usingWindows.Devices.Gpio;usingwindows.foundation;usingWindows.Foundation.Collections;usingWindows.UI.Xaml;usingWindows.UI.Xaml.Controls;usingWindows.UI.Xaml.Controls.Primitives;usingWindows.UI.Xaml.Data;usingWindows.UI.Xaml.Input;usingWindows.UI.Xaml.Media;usingWindows.UI.Xaml.Navigation;// https://go.microsoft.com/fwlink/?LinkId=402352"Blank page" item template is described on &clcid=0x804namespacemyiot{/// <summary> ///a blank page that can be used for itself or to navigate inside a Frame. /// </summary> Public Sealed Partial classMainpage:page {PrivateGpiopin Pin4; PrivateGpiopin Pin5input; PrivateDispatcherTimer timer1; PublicMainPage () { This. InitializeComponent (); Gpiocontroller Gpio=Gpiocontroller.getdefault (); Pin4= Gpio. Openpin (4); Pin5input= Gpio. Openpin (5); Pin4. Setdrivemode (Gpiopindrivemode.output); Pin5input.setdrivemode (Gpiopindrivemode.input); Timer1=NewDispatcherTimer (); Timer1. Interval= Timespan.frommilliseconds ( -); Timer1. Tick+=Timer1_Tick; Timer1. Start (); } Private voidTimer1_Tick (ObjectSenderObjecte) {gpiopinvalue value=Pin5input.read (); if(Value = =gpiopinvalue.high) {pin4. Write (Gpiopinvalue.high); This. Infotext.text ="Pin5input is high"; } Else if(Value = =gpiopinvalue.low) {pin4. Write (Gpiopinvalue.low); This. Infotext.text ="Pin5input is low"; } } Private voidSubmitaction_click (Objectsender, RoutedEventArgs e) {App.Current.Exit (); } }}
Remember to add: Windows IoT Extensions for the UWP reference.
Blinkled Lighting The first LED light (C #)