The serial monitor displays only case 0

Post #9 by @alto777 where he provides an example that uses a range of values for the test expression in each case rather than just a single value. I wasn't aware that was possible, e.g.:

It perhaps looks neater than having several if statements:

if ( (adcValue >= btn1Min) && (adcValue <= btn1Max) ) { }

not sure, just compare post #1 and #14

How about what I was talking about in post #7, you didn't have any external pullup resistors.
You needed them to pull the input pin to Vcc when your button isn't shorting the input to gnd.
Implementing "INPUT_PULLUP" accomplished the same thing.

Tom.... :smiley: :+1: :coffee: :australia:

If its a button, why are you analog reading instead of digital reading.
Check that you can setup pin 36 as a digital input. = see the circuit

Are you using an ESP32, if so what model? = yes

There are 4 buttons and they are all connected to Analog Pin 0. Each press has the different voltage value dropped with resistor(s). So analogRead function is needed.

Post #7;

It would have helped back at post #7

Tom.... :smiley: :+1: :coffee: :australia:

When I see all those GPIO pins I have to wonder why you are using analog input to get one pin to do the work of five.

It would be one thing if that hack was reliable and easy to program, but five digital inputs would be better in almost any way of measuring.

Just sayin'.

a7

sometime I am using ESP32C6 where is much less pins

Mebbe so, @alto777, but I use a similar technique to scan up to 27 buttons on A7 of a Nano. It takes some work to code succinctly, and there are differences in my circuit that improve accuracy and response, but the approach of using resistors and an analog input is quite valid and robust, when coded decently. Five equal resistors shouldn't be an issue. I'm reading buttons up to 15' away without any issues to date.

My circuit differs quite a bit, but the end result is a voltage at the input that clearly indicates which button has been pressed, The underlying assumption is, no one will be foolish enough to press 2 or more buttons simultaneously.

As for the OP's circuit, it's not ideal, but not fatally flawed as far as I can see.