I am trying to figure out why my simple button works so randomly
This is the code that worked in the past:
Code: Select all
#define BUTTON 34
#define PRESSED HIGH
#define NOT_PRESSED LOW
void setup {
pinMode(BUTTON,INPUT_PULLUP);
delay(50);
digitalWrite(BUTTON, NOT_PRESSED);
int q = 0;
if (digitalRead(BUTTON) == PRESSED) {
q++;
}
delay(2000);
if (digitalRead(BUTTON) == PRESSED) {
q++;
}
}
void loop {}
With the following changes, the button behaves randomly:
Code: Select all
#define BUTTON 34
#define PRESSED LOW
#define NOT_PRESSED HIGH
I've checked with the multi-meter and the button works.
This is the setup:
https://i.postimg.cc/5NMQ1y2P/20190508-115947.jpg