简体   繁体   English

使用UWP c#读取gpio的树莓派PI值

[英]raspberry PI reading value of gpio with UWP c#

I'm using Windows IOT core on a raspberry pi 3. I'm trying to determine whether a switched is turned on or not. 我在树莓派3上使用Windows IOT核心。我试图确定是否已打开开关。 Every time the timer in the program ticks time will be added to run time or down time depending on the state of the switch. 每次程序滴答时间中的计时器将被添加到运行时间或停机时间,具体取决于开关的状态。

All of the examples I've found use interrupts to catch the change of state of a gpio pin. 我发现的所有示例都使用中断来捕获gpio引脚状态的变化。 This would work, except for when the pi is first turned on. 这将起作用,除了首次打开pi时。 It could be minutes or hours before the first interrupt and that time should be accounted for correctly. 第一次中断可能需要几分钟或几小时,并且应该正确考虑该时间。

I'm looking for the correct syntax for the if statement. 我在寻找if语句的正确语法。 switchPin.Read == GpioPinValue.High isn't correct. switchPin.Read == GpioPinValue.High不正确。

    private void Timer_Tick(object sender, object e)
    {
        //Every second add time to run or down time


        if (switchPin.Read == GpioPinValue.High)
        {
            sngRunTime += 1;
        }
        else
        {
            sngDownTime += 1;
        }
    }

I feel like an idiot. 我感觉像个白痴。 The code is correct except for the missing parentheses after switchPin.read(). 该代码是正确的,除了switchPin.read()之后缺少括号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM