I have 6 buttons attached with a number of resistors to analog pin 36 of the ESP32 so that I can attach multiple buttons on the same analog pin. (Like in this example: https://www.youtube.com/watch?v=Y23vMfynUJ0)
The output is nothing, except for the button that has no resistor value (the first one) in the array. However, it only prints two 1s in the serial output.
I think the problem is that "attachInterrupt(digitalPinToInterrupt(BTNS), isrbuttons, CHANGE" is expecting a change. Going from fully High to fully Low or the other way around. I was hoping it would trigger when there was any change. However, this wouldn't explain why it only prints two values in the serial output.
I would highly appreciate any suggestions on achieving something similar to what I'm trying to do below!
Alex
The code I am running now looks like this:
Code: Select all
#define BTNS 36
volatile bool iButtons = false;
void IRAM_ATTR isrbuttons()
{
iButtons = true;
}
int8_t FuncButtonAnalogueRead()
{
iButtons = false;
int16_t JButRead = analogRead(BTNS);
if (JButRead > 3500 < 4500)
{
return 1;
}
if (JButRead > 1600 < 3500)
{
return 2;
}
if (JButRead > 1000 < 1600)
{
return 3;
}
if (JButRead > 700 < 1000)
{
return 4;
}
if (JButRead > 600 < 700)
{
return 5;
}
if (JButRead > 450 < 600)
{
return 6;
}
}
void setup()
{
Serial.begin(115200);
pinMode(BTNS, INPUT);
attachInterrupt(digitalPinToInterrupt(BTNS), isrbuttons, CHANGE);
}
void loop()
{
if (iButtons)
{
int8_t ENButton = FuncButtonAnalogueRead();
Serial.println(ENButton);
}
}