Group called by interrupt no longer recognizes delays

I have a section of code called "group1" that I have given priority to by assigning it as an interrupt:


I call group1 by a push button set up and an if/else if scenario :

if(buttonState1 ==HIGH) {


} else if(buttonState2 == HIGH) {

group2(); } else if(buttonState2==HIGH && buttonState1==HIGH) { group1(); }

This functions as expected with the exception of the delays in group1:

void group1() { // turn LED on for 1: digitalWrite(ledPin2, HIGH); delayMicroseconds(1000000); //Pulsewidth delay digitalWrite(ledPin2, LOW); delayMicroseconds(1000000); //delay between numbers }

For some reason after I declare group1 within the interrupt statement these delays are not recognized. The program executes super fast and there are no 1 second pauses between the LED going on and off. Are there ways to create delays within the interrupt so that I can get equal spacing between the LED coming on and off? THe code for group1 that I have posted is just section. The whole group1 and group2 code steps through a binary counting sequence from 1 to 15 using 4 LEDs for each group in identocal fasion. The only exception is that group1 is declared within the attachInterrupt and the delays have been altered as prescribed by Arduino's information page on interrupts, from"delay" to "delayMicroseconds".

There is usually no reason to use interrupts with push buttons.

Please read Nick Gammon's tutorial on interrupts and the requirements for ISR's.

jluca013: I have a section of code called "group1" that I have given priority to by assigning it as an interrupt:

This is so wrong I don't know how to explain it.

An Interrupt Service Routine (your group1() ) is a piece of code that should ONLY be called when some external device causes the voltage on the pin to change.

You would NOT call that ISR from within loop().

The code in an ISR should only take as few microseconds as possible to complete so that the interrupt is completed quickly. Do not put any delay() commands in an ISR.

I suspect you don't need an ISR in your code at all.


having it triggered on an interrupt does nothing to change what happens when you call it from regular code. You might need to go read up on what interrupts actually do.

All of what the previous posts said is true. Not only that, but your delayMicroseconds will not work? Why you ask? Well lets look at the delayMicroseconds function.


us: the number of microseconds to pause (unsigned int) <–See that int right there, maximum 65535

Then there is this!
Currently, the largest value that will produce an accurate delay is 16383. This could change in future Arduino releases. For delays longer than a few thousand microseconds, you should use delay() instead.

Furthermore, putting 1000000 will never work, you MUST put a UL or L after it to tell the program to treat it as an unsigned long or long instead of a 16 bit int.

Lastly, please put your code in code tags

So you code does not get distorted by some things such as array references, 
otherwise something like array[i] = 1; may get turned into this...

array = 1; See what happens here?