1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| using System;
using Windows.Devices.Gpio;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
// Pour plus d'informations sur le modèle d'élément Page vierge, consultez la page http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace premier
{
/// <summary>
/// Une page vide peut être utilisée seule ou constituer une page de destination au sein d'un frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
InitGPIO();
}
private void InitGPIO()
{
var gpio = GpioController.GetDefault();
touchPin = gpio.OpenPin(TOUCH_PIN);
if (touchPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
touchPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
else
touchPin.SetDriveMode(GpioPinDriveMode.Input);
touchPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
touchPin.ValueChanged += TouchPin_ValueChanged;
}
private void TouchPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
{
var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
if (e.Edge == GpioPinEdge.FallingEdge)
{
rectangle1.Stroke = yellowBrush;
}
});
}
private const int TOUCH_PIN = 5;
private GpioPin touchPin;
// private GpioPinValue touchPinValue = GpioPinValue.Low;
private SolidColorBrush yellowBrush = new SolidColorBrush(Windows.UI.Colors.Yellow);
private SolidColorBrush orangeBrush = new SolidColorBrush(Windows.UI.Colors.Orange);
}
} |
Partager