BlinkLED 点亮第一个LED灯(C#)

界面:

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
            <TextBox Name="infoText" Text="Ready" FontSize="50" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBox>
            <Button Name="submitAction" FontSize="50" HorizontalAlignment="Center" VerticalAlignment="Center" Click="submitAction_Click">Exit</Button>
        </StackPanel>

代码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Devices.Gpio;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x804 上介绍了“空白页”项模板

namespace MyIoT
{
    /// <summary>
    /// 可用于自身或导航至 Frame 内部的空白页。
    /// </summary>
    public sealed partial class MainPage : Page
    {
        private GpioPin pin4;
        private GpioPin pin5Input;
        private DispatcherTimer timer1;
        public MainPage()
        {
            this.InitializeComponent();

            GpioController gpio = GpioController.GetDefault();
            pin4 = gpio.OpenPin(4);
            pin5Input = gpio.OpenPin(5);
            pin4.SetDriveMode(GpioPinDriveMode.Output);
            pin5Input.SetDriveMode(GpioPinDriveMode.Input);

            timer1 = new DispatcherTimer();
            timer1.Interval = TimeSpan.FromMilliseconds(500);
            timer1.Tick += Timer1_Tick;
            timer1.Start();

            
        }

        private void Timer1_Tick(object sender, object e)
        {
            GpioPinValue value = pin5Input.Read();

            if (value == GpioPinValue.High)
            {
                pin4.Write(GpioPinValue.High);
                this.infoText.Text = "pin5Input is High";
            }
            else if (value == GpioPinValue.Low)
            {
                pin4.Write(GpioPinValue.Low);
                this.infoText.Text = "pin5Input is Low";
            }
        }

        private void submitAction_Click(object sender, RoutedEventArgs e)
        {
            App.Current.Exit();
        }
    }
}

 

记得要添加:Windows IoT Extensions for the UWP 引用。

 

转载于:https://www.cnblogs.com/codespark/p/7191146.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值