简体   繁体   中英

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. 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. This would work, except for when the pi is first turned on. 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. switchPin.Read == GpioPinValue.High isn't correct.

    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().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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