Alternative to delay() during interrupt

Hi all,

I have an interrupt which is supposed to cycle through different modes on my LCD screen. The problem I have is that while my interrupt is activated, I would like the LCD screen to display which options you are running through. My LCD screen requires the program to have a delay after the data has been written to the LCD because I also have a clearLCD function, so the user wouldn't be able to see what is written as it is cycling through the program too fast. So what I am asking is how can I replace the delay function so that the LCD will display the options because I know that you cant have delay functions in an interrupt?
Here is my function which is called when the interrupt is activated:

void tripuino::funkvor(volatile int *function){
  int pot;
    while(digitalRead(4) == LOW){          //While "Enter not being pressed.."
      pot = analogRead(0);
      if(pot <= 1023 && pot >= 774){        //value between 1023 - 774 display 0 etc..
        *function = 1;
        lcd.clearLCD();
        lcd.goTo(0);
        Serial.print("Choose Function:");
        lcd.goTo(18);
        Serial.print("Speed (KM/H)");    
        //delay(100) replacement here
      }
      else{
        if(pot < 774 && pot >= 525){
          *function = 2;
          lcd.clearLCD();
          lcd.goTo(0);
          Serial.print("Choose Function:");
          lcd.goTo(19);
          Serial.print("Speed (MPH)");
         //delay(100) replacement here
        }
        else{
          if(pot < 525 && pot >= 190){
            *function = 3;
            lcd.clearLCD();
            lcd.goTo(0);
            Serial.print("Choose Function:");
            lcd.goTo(16);
            Serial.print("Avg.Speed (KM/H)");
            //delay(100) replacement here
          }
          else{
            if(pot < 190 && pot >= 55){
              *function = 4;
              lcd.clearLCD();
              lcd.goTo(0);
              Serial.print("Choose Function:");
              lcd.goTo(16);
              Serial.print("Avg. Speed (MPH)");
              //delay(100) replacement here
            }
            else{
              if(pot < 55 && pot >= 28){
                *function = 5;
                lcd.clearLCD();
                lcd.goTo(0);
                Serial.print("Choose Function:");
                lcd.goTo(17);
                Serial.print("Distance (KM)");
                //delay(100) replacement here
              }
              else{
                if(pot < 28 && pot >= 9){
                  *function = 6;
                  lcd.clearLCD();
                  lcd.goTo(0);
                  Serial.print("Choose Function:");
                  lcd.goTo(17);
                  Serial.print("Distance (MI)");
                 //delay(100) replacement here
                }
                else{
                  if(pot < 9 && pot >= 4){
                    *function = 7;
                    lcd.clearLCD();
                    lcd.goTo(0);
                    Serial.print("Choose Function:");
                    lcd.goTo(18);
                    Serial.print("Travel Time");
                   //delay(100) replacement here
                  }
                  else{
                    if(pot == 3){
                      *function = 8;
                      lcd.clearLCD();
                      lcd.goTo(0);
                      Serial.print("Choose Function:");
                      lcd.goTo(20);
                      Serial.print("Security");
                      //delay(100) replacement here
                    }
                    else{
                      if(pot == 2){
                        *function = 9;
                        lcd.clearLCD();
                        lcd.goTo(0);
                        Serial.print("Choose Function:");
                        lcd.goTo(17);
                        Serial.print("Security BETA");
                       //delay(100) replacement here
                      }
                      else{
                        if(pot == 1){
                          *function = 1;
                          lcd.clearLCD();
                          lcd.goTo(0);
                          Serial.print("Choose Function:");
                          lcd.goTo(17);
                          Serial.print("END - Go Back");
                         //delay(100) replacement here
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
}

Thanks in advance

I can't really comment on your code, other then to say if that is indeed a ISR it goes against most normal advice and recommendations for ISRs. An ISR should be as short and fast as possible as during it's running all other system interrupts are disabled.

It's normal practice to have an ISR just test something and just set or reset a global variable and then return to the normal loop function where it can read the various flag values and perform tasks as appropriate. The main loop function should be where most of the action takes place.

As someone over at the AVRfreaks site said: A ISR should be used like a one bathroom house with 15 guests, get in, do your business, and get out. :wink:

Lefty

Thank you for the reply Lefty,
I have heard that before. I guess Ill just have to keep my project a little less fancy, or find another way of executing my code. I think I might just end up causing the interrupt to change the value of an int. In my main loop ill have it check if the int is 0 or 1 before it executes the other commands. And if the interrupt was executed, the int will be 1, so then it'll execute the above function and return the value of int to 0.

I love how there are so many ways of achieving ones goal in programming. Its just a pain to find one which works correctly, but efficiently. :slight_smile:

Thanks again,
Firestork