Interrupt problem with Pro-mini

Hello,

The following code is supposed to lit 2 leds (with a delay between them) whenever button is pressed. And also when first booted. When booted, it does it perfectly.

However, when button is pressed, both leds flash twice and nothing else happened.

I have tried "Rising" instead of "High" with no difference.

Debounce is important as the button is very noisy.

Appreciate any help.

//Arduino pro/mini running

long debouncing_time = 15; //Debouncing Time in Milliseconds
volatile unsigned long last_micros;
#define poweruppin 3
#define playbackpin 4
const byte interruptPin = 2;
volatile byte state = LOW;
long intervalogle = 10000; // interval at which to do something (milliseconds) 1 minute = 60,000
unsigned long previousMillisogle = 0;
long intervalaksam = 5000; 
unsigned long previousMillisaksam = 0;
int firstrun = 1;
void setup() 
{
pinMode(poweruppin, INPUT);
pinMode(playbackpin, INPUT);
pinMode(interruptPin, INPUT_PULLUP);
digitalWrite(poweruppin, LOW); //OFF by default
digitalWrite(playbackpin, LOW); 
attachInterrupt(digitalPinToInterrupt(interruptPin), debounceInterrupt, HIGH);
Serial.begin(115200);
}

void loop() 

{
if (firstrun == 1)
            {
              Serial.println("First run baby...");
                  showtime();
            }
/*
        unsigned long currentMillisogle = millis();
        if(currentMillisogle - previousMillisogle >  intervalogle)
            {
             previousMillisogle = currentMillisogle;  
                  showtime();
            }
*/
}

void showtime()
{
  firstrun = 0;
  Serial.println("Power up...");
  digitalWrite(poweruppin, HIGH);
  delay(5000);
  Serial.println("Playback...");
  digitalWrite(playbackpin, HIGH);
  delay(30000); //wait for playback to complete
  digitalWrite(poweruppin, LOW);
  digitalWrite(playbackpin, LOW);
  Serial.println("All Off...");
}

void debounceInterrupt() {
  if((long)(micros() - last_micros) >= debouncing_time * 1000) {
    Interrupt();
    last_micros = micros();
  }
}


void Interrupt() {
  Serial.println("interrupt happened...");
  showtime();
}

I notice that you are printing inside a function called from an ISR.

Interrupts are disabled when an ISR is active Serial printing uses interrupts

Can you see that there might be a problem ?

I disabled it, with no avail.

Why are you using an interrupt to detect a button press? Humans are very slow and polling should be fine.

...R

As I mentioned, button is noisy. But the though crossed my mind. I'll try it now.

Yes. No interrupt is better.

Arduino warns against micros in interrupt. I'll research that as well.

Thank you all for your input.

Regards

When you in interrupt - all other interrupts are disabled and millis is not "ticking" as well. And delay() doesn't work. You can enable interrupt using sei() at the beginning of interrupt(). But you whole design is not good.

UPD. It's absolutely valid approach to serve buttons by interrupt, but design should be completely different.

alesam: You can enable interrupt using sei() at the beginning of interrupt().

NOT a good idea for a beginner :)

...R