Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. using Windows.UI.Xaml.Controls;
  2. using Windows.Devices.Gpio;
  3.  
  4. namespace GPIOIntroPi
  5. {
  6. public sealed partial class MainPage : Page
  7. {
  8. private const int LED_PIN = 27;
  9. private const int PB_PIN = 5;
  10. private GpioPin pin;
  11. private GpioPin pushButton;
  12.  
  13. public MainPage()
  14. {
  15. InitializeComponent();
  16.  
  17. Unloaded += MainPage_Unloaded;
  18.  
  19. InitGPIO();
  20. }
  21.  
  22. private void InitGPIO()
  23. {
  24. var gpio = GpioController.GetDefault();
  25.  
  26. if (gpio == null)
  27. {
  28. pin = null;
  29. GpioStatus.Text = "There is no GPIO controller on this device.";
  30. return;
  31. }
  32. pushButton = gpio.OpenPin(PB_PIN);
  33. pin = gpio.OpenPin(LED_PIN);
  34.  
  35. pushButton.SetDriveMode(GpioPinDriveMode.Input);
  36. pin.Write(GpioPinValue.Low);
  37. pin.SetDriveMode(GpioPinDriveMode.Output);
  38.  
  39. GpioStatus.Text = "GPIO pin initialized correctly.";
  40. }
  41.  
  42. private void MainPage_Unloaded(object sender, object args)
  43. {
  44. pin.Dispose();
  45. pushButton.Dispose();
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement