Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Windows.UI.Xaml.Controls;
- using Windows.Devices.Gpio;
- namespace GPIOIntroPi
- {
- public sealed partial class MainPage : Page
- {
- private const int LED_PIN = 27;
- private const int PB_PIN = 5;
- private GpioPin pin;
- private GpioPin pushButton;
- public MainPage()
- {
- InitializeComponent();
- Unloaded += MainPage_Unloaded;
- InitGPIO();
- }
- private void InitGPIO()
- {
- var gpio = GpioController.GetDefault();
- if (gpio == null)
- {
- pin = null;
- GpioStatus.Text = "There is no GPIO controller on this device.";
- return;
- }
- pushButton = gpio.OpenPin(PB_PIN);
- pin = gpio.OpenPin(LED_PIN);
- pushButton.SetDriveMode(GpioPinDriveMode.Input);
- pin.Write(GpioPinValue.Low);
- pin.SetDriveMode(GpioPinDriveMode.Output);
- GpioStatus.Text = "GPIO pin initialized correctly.";
- }
- private void MainPage_Unloaded(object sender, object args)
- {
- pin.Dispose();
- pushButton.Dispose();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement