needing help adding to code below

i need to add an interrupt function to this code so that there is one led light upon startup, then when the button is pressed it will make a second led come on and blink. and the first LED turn off. while the second led is blinking i need an interrupt function so that when a second button is pressed it will light a 3rd led until the button is unpressed, which it will then return to blinking the led until the first button is pressed again to turn the first led back on. (im using a relay for the switching of the leds)

// this constant won't change:
const int buttonPin = 8; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to
// Variables will change:
boolean buttonState = 0; // current state of the button
boolean lastButtonState = 0; // previous state of the button

void setup()
{
// initialize the button pin as a input with internal pullup enabled
pinMode(buttonPin, INPUT_PULLUP);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}

void loop()
{
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState)
{
// if the state has changed, increment the counter
if (buttonState == LOW)
{
// if the current state is LOW then the button
// went from off to on:
Serial.println("on");
digitalWrite(ledPin, !digitalRead(ledPin)); // toggle the output
}
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
}

For that purpose you don't need interrupts. See the "several things at the same time" entry on top of the forum.

for this application its required that there present in the code. im trying to get the code to initiate a red led to come on the n with 1 button press a green led comes on and blinks, then when the second button is pressed it interups the blink and turns on a yelllow led until the interupt is over, then returns to binking util the first buton is pressed

Learn how to avoid delay() by using BWD ‘Blink Without Delay techniques’.
Learn how to debounce switches.
Learn how to use switch change in state detection.
Learn how to make a state machine.

See examples in the Tutorial forum.

Show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components.
Posting images:
https://forum.arduino.cc/index.php?topic=519037.0

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

kevindiamond:
for this application its required that there present in the code.

Is this for a school project?

yes this is

Then it isn't likely that anyone here is just going to write the code for you.
Here is a good explanation of Arduino interrupts so that you can do it yourself.

i don't want the code written for me im just trying to figure out the best way to add an interrupt function in that platform to accomplish the function. i messed up when uploading my code aswell

Unless you were told to use interrupts, don’t.

Interrupts are ‘not’ a good fit with slow bouncy switches.

Scan your switches at a 50ms rate to deal with switch bounces.

Look for a change in state for each switch, do things according to switch state changes not switch levels.

When you need to create a timer, use the millis() function mentioned in the readings.
https://forum.arduino.cc/index.php?topic=223286.0

State machine programming can often solve complex coding issues.

Use Flags to notify routines to run or not run.

okay, i would it work better if i were to use internal interrupts and then have only 1 of them controled by a button press?

This is the third time you've been told that you shouldn't use an interrupt:

delay(50);In 50 milliseconds, the processor executes up to 800 000 instructions, all of them wasted in your delay.

You do not need an interrupt.