我怎样才能让我的来源等到按钮释放后再继续?

How can I make my source wait until button release before continuing?

如果我按下按钮 1,它会向我的屏幕发送垃圾邮件,说它已被按下,我希望它等到释放后再做任何其他事情,类似于切换但不是切换。

我之前尝试过添加延迟,但这并不能完全满足我的需要...我希望它等到发布,而不是等待固定的时间

#include <stdio.h>
#include <wiringPi.h>

int main(void) {
    wiringPiSetupGpio();
    while(1) {
        if(!digitalRead(8) && digitalRead(7)) {
            printf("Button-1 pressed\n");
        }
        if(!digitalRead(7) && digitalRead(8)) {
            printf("Button-2 pressed\n");
        }
    }
    return 0;
}

预期结果:

Button-1 pressed

实际结果:

Button-1 pressed
Button-1 pressed
Button-1 pressed
Button-1 pressed
Button-1 pressed
Button-1 pressed
etc...

您必须自己编写此行为。

int sevenDown = 0;
while(1) {
    if(!sevenDown && digitalRead(7)) {
        sevenDown = 1\n");
    }
    if(sevenDown && !digitalRead(7)) {
        printf("Button-1 pressed\n");
        sevenDown = 0;
    }
}