Created
September 5, 2017 23:16
-
-
Save pandalion98/ccebdcaa4a45dab3b1be42037ad218a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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