Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.