I'm trying to print a message every time a button is pressed, and so far it's working fine, but the message is printed several times (somewhere around 4000 times) and I'd like it to be printed only once.
How can I fix this? I've tried several forms of validation that worked in parts, however, when I use them, the software ends or exits in the loop.
#include <stdio.h>
#include <wiringPi.h>
int main(){
wiringPiSetup();
pinMode(25, OUTPUT);
pinMode(3, INPUT);
int pressed =0;
while (1){
if(digitalRead(3)==1){
//printf("pressed");
pressed++;
printf("RESULT %d \n",pressed);
}
}
return 0;
}
switch debounce