Help with an immediate Interrupt

Hello everyone, I'm new, but I have developed a program with then has been tweaked by others. I am having some difficulty with one are of the software code below. This code is for a BMX practice gate and where I am having problems is in the "Loop". When I depress my start button the following should happen:
1 - delay of 2 seconds for the BMX rider to get setup
2 - an audio file starts the cautionary cadence which last for 5.3 seconds
3 - after the 5.3 seconds there is a random delay generation between .1 sec and 2.7 seconds.

This all works fine, but if during the cautionary cadence (within the 5.3 seconds) I press the start button again, I need the loop to stop and immediately jump to the abort sequence. My problem is that I believe the delay within the attachinterrupt won't allow this. Can someone look at the code I have and tell me a way around this. I have highlighted it in BOLD Green text.
Any help you can provide would be great and very much appreciated!!!

I am loading all the code so you can see how this bad boy works:

int outPin = 1; // communication line to the MP3 Trigger
int startpbVal = 0; // variable for reading the Start PB state
int startpbState=0; // variable for holding the start PB state
volatile int val = 0; // initiate dummy variable for use as interrupt loop delay
volatile int abt=0; // initialize abort counter at 0

const int startpbPin = 2; // Start pushbutton
const int gateupPin = 3; // Initialization/Reset sequence pushbutton
const int grnledPin = 5; // Green LED on the light tree
const int yelled2Pin = 6; // Yellow #2 LED on the light tree
const int yelled1Pin = 7; // Yellow #1 LED on the light tree
const int redledPin = 8; // Red LED on the light tree
const int upsolPin = 9; // Solenoid that holds the gate up
const int dwsolPin = 10; // Solenoid that holds the gate down
long randNumber; // sets variable rand "random" to a long integer.

void setup() {

Serial.begin(9600); //Initialize serial communications

pinMode(outPin, OUTPUT); //transmit info to MP3 Trigger to play specified track

pinMode(redledPin, OUTPUT); //Output to Red LED transistor for LED on light tree
pinMode(yelled1Pin, OUTPUT); //Output to Yellow1 LED transistor for LED on light tree
pinMode(yelled2Pin, OUTPUT); //Output to Yellow2 LED transistor for LED on light tree
pinMode(grnledPin, OUTPUT); //Output to Green LED transistor for LED on light tree

pinMode(upsolPin, OUTPUT); //Output to Gate Up Solenoid transistor
pinMode(dwsolPin, OUTPUT); //Output to Gate Down Solenoid transistor

pinMode(startpbPin, INPUT); //start and abort pushbutton (abort not funtioning yet)
pinMode(gateupPin, INPUT); //gate up PB which functions only once for now.

digitalWrite(upsolPin, LOW); //Part of the command to drive the solenoid down so that the gate doesn't go up out of control
digitalWrite(dwsolPin, HIGH); //part of the command to drive the solenoid down so that the gate doesn't go up out of control
}

void loop(){
digitalWrite(redledPin, LOW); //reset red light from abort function call
abt=0; //reset abort counter

if (digitalRead(gateupPin) == HIGH) { //check to see if the gate up button is pressed.
** gateup(); //go to gateup sub-routine **
**} **

startpbVal = digitalRead(startpbPin); //read input value and store it in startpbVal

if (startpbVal != startpbState){ //the button state has changed!
** delay(0500); //delay half a second to allow the user to get their finger off the button**

** attachInterrupt(0,abort, RISING); //when input goes from low to high, perform the abort function**

** Serial.begin(38400); //if analog input pin 0 is unconnected, random analog**
** randomSeed(analogRead(0)); //noise will cause the call to randomSeed() to generate**
** //different seed numbers each time the sketch runs.**
** //randomSeed() will then shuffle the random function. **

** digitalWrite(redledPin, LOW); //sets Red LED to off**
** digitalWrite(yelled1Pin, LOW); //sets Yellow LED #1 to off**
** digitalWrite(yelled2Pin, LOW); //sets Yellow LED #2 to off**
** digitalWrite(grnledPin, LOW); //sets Green LED #1 to off**

** //Beginning of the cadence section **
** delay(2000); //two second delay to allow the ride a chance to get settled.**

** Serial.write('t'); //lowercase "t" must be in single quotes…**
** Serial.write(1); //commands MP3 trigger to play track001 - UCI cadence**

** delay(5350); //starts the 5.3 seconds delay for the cadence to complete**
** detachInterrupt(0); //removes the interupt function from the start pin**

** if(abt>2){ //if abt=1, then**

** Serial.write('t'); //command to mp3 trigger to initialize**
** Serial.write(4); //command to mp3 trigger to play track 4**

** digitalWrite(redledPin, HIGH); //while playing abort tone, hold red light on**
** delay(1000);**
** loop(); //exit start sequence**
** }**
else{ //if pressed, then perform start sequence

randNumber = random(100, 2700); //Generates a random number between 100 and 2700 (.1 sec to 2.7 sec)
delay(randNumber); //sets random number into delay for start circuit

Serial.write('t'); //lowercase "t" must be in single quotes…
Serial.write(2); //causes the MP3 trigger to play track002

delay(0060);

digitalWrite(redledPin, HIGH); //sets the RED LED to on
delay(0120); //sets delay for .120 seconds
digitalWrite(yelled1Pin, HIGH); //sets the Yellow LED #1 to on
delay(0120); //sets delay for .126 seconds
digitalWrite(yelled2Pin, HIGH); //sets the Yellow led #2 to on
delay(0120); //sets delay for .126 seconds
digitalWrite(grnledPin, HIGH); //sets the Green LED to on
digitalWrite(upsolPin, LOW); //command to drop the gate
digitalWrite(dwsolPin, HIGH); //command to drop the gate

delay(2250); //required delay for tone and lights

digitalWrite(redledPin, LOW); //sets Red LED to off
digitalWrite(yelled1Pin, LOW); //sets Yellow LED #1 to off
digitalWrite(yelled2Pin, LOW); //sets Yellow LED #2 to off
digitalWrite(grnledPin, LOW); //sets Green LED #1 to off

delay(3000); //three second delay before the gate automatically goes up
gateup(); //calls the reinitialization sequence
}
}

}

void gateup(){
Serial.begin(38400); //if analog input pin 0 is unconnected, random analog
Serial.write('t'); //command to mp3 trigger to initialize
Serial.write(3); //command to mp3 triggger to play track 3

digitalWrite(grnledPin, HIGH); //sets the Green LED to on
delay(2250); //delay to allow initialization tone to complete

digitalWrite(upsolPin, HIGH); //actuate the upward driving solenoid
digitalWrite(dwsolPin, LOW); //deactivate the downward driving solenoid
digitalWrite(grnledPin, LOW); //signal completion of the initialization sequence

return; //return from initialization function
}

void abort(){

val=0; //implement a delay funtion (inside an interrupt function
while(val<5000){ //delay calls do not function, )
val++;
}

abt=abt++; //increment button press counter
return; //return from abort function
}

It isn't normal to specify delays in octal - are "0500", "0060", "0120" really what you want?
I doubt you really need interrupts, and if you got rid of of all the delays, you'd probably manage it.

Please use CODE TAGS when posting code.

In other words see how the BlinkWithoutDelay example works... http://arduino.cc/en/Tutorial/BlinkWithoutDelay

Sorry about the code. New to the Forum format.

The delays are in not in Octal, or at least thats how I started. Let me explain the code a bit more.

We have an audio file that plays for 5.3 seconds from an MP3 Trigger in a start sequence for this BMX gate controller. I only want to abort the within this 5.3 seconds, but it would seem like I need the delay so that I don't continue to run the remaining code while the MP3 is playing. Essentially that is why I am using a lot of delays.

I suppose the question I have is, is there another method of delaying the code without using DELAY allowing the the interrupts to work? This issue is the last one plaguing my code.

Thank you so much for your help and I hope you can solve my woes!

Mike

Re-read reply #2.

Yes, the delays I pointed out are in octal.

So I have modified my code and maybe you can tell me if I have the correct syntax please

long intervaltr1 = 5300;                           // sets variable intervaltr1 as the intervals for MP3 track #1 in milliseconds (5.3 seconds)

  //Beginning of the cadence section  
     delay(2000);                           //two second delay to allow the ride a chance to get settled.
 
     Serial.write('t');                     //lowercase "t" must be in single quotes…
     Serial.write(1);                       //commands MP3 trigger to play track001 - UCI cadence
  
     intervaltr1;                           //starts the 5.3 seconds delay for the cadence to complete
     detachInterrupt(0);                     //removes the interupt function from the start pin
     
     if(abt>2){                            //if abt=1, then
  
      
                Serial.write('t');                    //command to mp3 trigger to initialize
                Serial.write(4);                      //command to mp3 trigger to play track 4
                
                digitalWrite(redledPin, HIGH);        //while playing abort tone, hold red light on
                delay(1000);
                loop();

the program complies, but I can't load it in my board just yet.

Thanks guys, I am a newbie at this and I do appreciate your help. Thanks for being patient.

Mike

If it compiles, the syntax is correct, so there is no need for us to comment.
Semantics are a different matter.
You've still got delays in there.
If you get rid of them, your interrupts will not be necessary.

     intervaltr1;                           //starts the 5.3 seconds delay for the cadence to complete

Huh? No it doesn't.


     if(abt>2){                            //if abt=1, then

You mean:

     if(abt>2){                            //if abt is greater than 2, then

                loop();

If this is inside the loop() function you are looping within loop. You will run out of RAM in a few microseconds.

Read this for doing multiple things at once:

Besides all the code fixes it seems to me that the best abort method might be to turn the power off.