[SOLVED] GPIO 33-35 button strange behavior. Changing value without button being pressed !
Posted: Wed May 08, 2019 8:28 am
Hello !
I am trying to figure out why my simple button works so randomly
This is the code that worked in the past:
With this code the button is either always PRESSED or NOT_PRESSED. Pressing it doesn't change its value.
With the following changes, the button behaves randomly:
With this code the button register values on its own. On startup it can be either PRESSED LOW or NOT_PRESSED HIGH. When it starts in NOT_PRESSED HIGH it works as expected. But when it starts in PRESSED LOW I can't use it.
I've checked with the multi-meter and the button works.
This is the setup:
https://i.postimg.cc/5NMQ1y2P/20190508-115947.jpg
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