Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private const int LED_PIN = 6;
- private const int PB_PIN = 5;
- private GpioPin pin;
- private GpioPin pushButton;
- private DispatcherTimer timer;
- private GpioPinValue pushButtonValue;
- public MainPage()
- {
- InitializeComponent();
- timer = new DispatcherTimer();
- timer.Interval = TimeSpan.FromMilliseconds(1);
- timer.Tick += Timer_Tick;
- timer.Start();
- Unloaded += MainPage_Unloaded;
- InitGPIO();
- }
- private void InitGPIO()
- {
- var gpio = GpioController.GetDefault();
- if (gpio == null)
- {
- pin = null;
- return;
- }
- pushButton = gpio.OpenPin(PB_PIN);
- pin = gpio.OpenPin(LED_PIN);
- pushButton.SetDriveMode(GpioPinDriveMode.Input);
- pin.Write(GpioPinValue.Low);
- pin.SetDriveMode(GpioPinDriveMode.Output);
- }
- private void MainPage_Unloaded(object sender, object args)
- {
- pin.Dispose();
- pushButton.Dispose();
- }
- private void FlipLED()
- {
- pushButtonValue = pushButton.Read();
- if (pushButtonValue == GpioPinValue.High)
- {
- pin.Write(GpioPinValue.High);
- }
- else if (pushButtonValue == GpioPinValue.Low)
- {
- pin.Write(GpioPinValue.Low);
- }
- }
- private void Timer_Tick(object sender, object e)
- {
- FlipLED();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement