Hi,
I'm using interrupts via two push button on Arduino Pro Mini (a clone one) to manage a menu on an oled display.
here is a piece of the code:
every thing works fine whene ther is no (or a small) delay in void loop !!!!
What I'm I doing wrong ???!!!
int buttonSelectPin = 2;
int buttonNavPin = 3;
volatile long debouncing_time = 320; //Debouncing Time in Milliseconds
volatile unsigned long last_micros;
void setup() {
pinMode(buttonSelectPin, INPUT_PULLUP); // enable internal pull-up resistor
pinMode(buttonNavPin, INPUT_PULLUP);
// attachInterrupt(digitalPinToInterrupt(pin), ISR, mode);
attachInterrupt(digitalPinToInterrupt(buttonSelectPin),selectInterrupt,FALLING);
attachInterrupt(digitalPinToInterrupt(buttonNavPin),navInterrupt,FALLING);
}
void loop() {
delay(200000);
}
//----------------------------------------------
// Check if Button Nav was pressed
//----------------------------------------------
void navInterrupt() {
if((long)(millis() - last_micros) >= debouncing_time)
{
last_micros = millis();
if (pageMenu==2)
{
selector++;
}
if (selector>4)
{
selector = 0;
}
}
}
//----------------------------------------------
// Check if Button Select was pressed
//----------------------------------------------
void selectInterrupt() {
if((long)(millis() - last_micros) >= debouncing_time)
{
last_micros = millis();
pageMenu++;
if (pageMenu>2)
{
pageMenu = 1;
}
}
}