Skip to content

Instantly share code, notes, and snippets.

@pandalion98
Created September 5, 2017 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandalion98/ccebdcaa4a45dab3b1be42037ad218a4 to your computer and use it in GitHub Desktop.
Save pandalion98/ccebdcaa4a45dab3b1be42037ad218a4 to your computer and use it in GitHub Desktop.
using Windows.Devices.Gpio;
namespace SampleCode {
public sealed partial class MainPage { // Dummy
// GPIO Pin 6, NOT header pin 6 (i.e. not pin 6 on the Pi)
private const int LISTEN_PIN = 6;
private GpioPin listenPin;
// Dummy
public MainPage() {
this.InitializeComponent();
}
void startListening() {
// Get an object that represents the device GPIO
var gpio = GpioController.GetDefault();
if (listenPin == null) {
// Open GPIO pin, and set to input mode
listenPin = gpio.OpenPin(LISTEN_PIN);
listenPin.SetDriveMode(GpioPinDriveMode.Input);
listenPin.ValueChanged += Pin_ValueChanged;
}
}
void stopListening() {
// Check for nullity, and cleanup if necessary.
if (listenPin != null) {
listenPin.ValueChanged -= Pin_ValueChanged;
listenPin.Dispose();
listenPin = null;
}
}
private void Pin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e) {
// Do Stuff
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment