I have a KY-040 rotary encoder with a push button wired to an ESP8266. My objective is to be able to detect if the button is pressed or not pressed on boot.
In the below code, if I hold the button down and power on the ESP8266, neither "IT'S STARTED" or "IT'S LOOPING" is printed in the serial monitor, even if I release the button. If I don't press the button, the code works as expected and prints "IT'S STARTED" followed by "IT'S LOOPING". It's as though the code gets stuck/halted if I press the button on boot.
Can someone explain why this is happening?
I would also appreciate suggestions on how I can detect the status (pressed/not pressed) of the button when the ESP8266 is powered up.
Here is my code:
void setup() {
pinMode(D3, INPUT_PULLUP);
Serial.begin(115200);
Serial.println("IT'S STARTED");
}
void loop() {
Serial.println("IT'S LOOPING");
delay(1000);
}
void setup() {
pinMode(D3, INPUT_PULLUP);
Serial.begin(115200);
Serial.println("IT'S STARTED");
}
void loop() {
Serial.println("IT'S LOOPING");
delay(1000);
}