LED and interrupt -- HELP Please

I’m a total beginner and have no real background in c++ programing, but for my school project I want to make optical theremin with 7 segment LED display. when I combined 2 program (7 segment LED display + optical theremin) they’re work as well, but when my teacher asked me to put a push button for the input, I being confused with the program.

I want the push button work as an interrupt, so when I press the button, the character of 7 segment LED should change asap, and the random character still running when the button is not pressed. But the fact is when I press the button, they will run random (it because I used a program for LED DICE) and I have to wait until the character is done and it will stop blinking until I press the button again. and if the button not press it’s just make tone signal without blinking any character.

Is there anyone can help me with the program please…?

int ROW1 = 1;
int ROW2 = 2;
int ROW3 = 3;
int ROW4 = 4;
int ROW5 = 5;
int ROW6 = 6;
int ROW7 = 7;

//pin definitions
#define PHONES 9  		 
// headphones connected to digital pin 9
#define PHOTOCELL 0 		
//photocell analog in pin 0

//Button pin
int buttonPin = 10;
int buttonState;

//Ran will be randomized from 1 to 6
long ran;

//variable definitions
long val = 0;       		
//stores raw value from photocell
long maxread = 0;    		
//maximum value from calibration phase
long minread = 1000;  		
// minimum value from calibration phase
double f = 0;         		
// frequency of sound
double normf = 0;    		
// normalized frequency 
double logf = 0;      		
// logarithm of normalized frequency
int ilogf = 0;        		
// rounded logarithm
int i = 0;            		
// loop dummy variable
double factor = 0;    		
// scaling factor for calibration
double shift = 0;     		
// shift for calibration
long maxfreq = 1048;  		
// maximum desired frequency after calibration
long minfreq = 131;   		
// minimum desired frequency after calibration

double gap = 1.148698355;  	
//ratio of consecutive notes (pentatonic)
// it's the 5th root of 2

void setup()

{ 
  //Set the pin of the button as an Input
  pinMode (buttonPin, INPUT);
  //This code line is necessary for a correct random
  randomSeed(analogRead(0));

  pinMode(ROW1, OUTPUT);
  pinMode(ROW2, OUTPUT);
  pinMode(ROW3, OUTPUT);
  pinMode(ROW4, OUTPUT);
  pinMode(ROW5, OUTPUT);
  pinMode(ROW6, OUTPUT);
  pinMode(ROW7, OUTPUT);
  
   pinMode(PHONES, OUTPUT);   	
 // sets the digital pin as output
   for (i = 0; i< 500; i++) {  		
// calibration loop runs for 5 seconds
   val = analogRead(PHOTOCELL);   	
// read photocell 
   tone(PHONES, val);         	
// play raw tone to guide calibration
   if (val > maxread) {        	
// as the values climb, store the largest
   maxread = val;
    }
    if (val < minread) {        	
// as the values drop, store the smallest
      minread = val;
    }  
    delay(10);                  	
// reasonable delay

}
  //Now we use the calibration to calculate scale and shift parameters
  factor = (double)(maxfreq - minfreq) / (double)(maxread - minread); 
// scale parameter
//it's like a slope
  
  shift = factor * minread - minfreq;  
//shift parameter: it's like an offset
}

void loop()
{                   
  //Read the status of the button 
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH){
  //Randomize from 1 to 6
    ran = random(7);


 // BEST
 if (ran == 1){
  // for B
  digitalWrite(ROW1, HIGH);
  digitalWrite(ROW4, HIGH);
  digitalWrite(ROW5, HIGH);
  digitalWrite(ROW6, HIGH);
  digitalWrite(ROW7, HIGH);
  theremin_sens();
  digitalWrite(ROW1, LOW);
  digitalWrite(ROW4, LOW);
  digitalWrite(ROW5, LOW);
  digitalWrite(ROW6, LOW);
  digitalWrite(ROW7, LOW);
  delay(500);
  // for E
  digitalWrite(ROW1, HIGH);
  digitalWrite(ROW2, HIGH);
  digitalWrite(ROW4, HIGH);
  digitalWrite(ROW6, HIGH);
  digitalWrite(ROW7, HIGH);
  theremin_sens();
  digitalWrite(ROW1, LOW);
  digitalWrite(ROW2, LOW);
  digitalWrite(ROW4, LOW);
  digitalWrite(ROW6, LOW);
  digitalWrite(ROW7, LOW);
  delay(500);
  // for S
  digitalWrite(ROW1, HIGH);
  digitalWrite(ROW2, HIGH);
  digitalWrite(ROW4, HIGH);
  digitalWrite(ROW5, HIGH);
  digitalWrite(ROW6, HIGH);
  theremin_sens();
  digitalWrite(ROW1, LOW);
  digitalWrite(ROW2, LOW);
  digitalWrite(ROW4, LOW);
  digitalWrite(ROW4, LOW);
  digitalWrite(ROW5, LOW);
  digitalWrite(ROW6, LOW);
  delay(500);
  // for  t
  digitalWrite(ROW1, HIGH);
  digitalWrite(ROW4, HIGH);
  digitalWrite(ROW6, HIGH);
  digitalWrite(ROW7, HIGH);
  theremin_sens();
  digitalWrite(ROW1, LOW);
  digitalWrite(ROW4, LOW);
  digitalWrite(ROW6, LOW);
  digitalWrite(ROW7, LOW);
  delay(1000);
  }

  //2013
  if (ran ==2){
  // for 2
  digitalWrite(ROW2, HIGH);
  digitalWrite(ROW3, HIGH);
  digitalWrite(ROW4, HIGH);
  digitalWrite(ROW6, HIGH);
  digitalWrite(ROW7, HIGH);
  theremin_sens();
  digitalWrite(ROW2, LOW);
  digitalWrite(ROW3, LOW);
  digitalWrite(ROW4, LOW);
  digitalWrite(ROW6, LOW);
  digitalWrite(ROW7, LOW);
  delay(500);
  // for 0
  digitalWrite(ROW1, HIGH);
  digitalWrite(ROW2, HIGH);
  digitalWrite(ROW3, HIGH);
  digitalWrite(ROW5, HIGH);
  digitalWrite(ROW6, HIGH);
  digitalWrite(ROW7, HIGH);
  theremin_sens();
  digitalWrite(ROW1, LOW);
  digitalWrite(ROW2, LOW);
  digitalWrite(ROW3, LOW);
  digitalWrite(ROW5, LOW);
  digitalWrite(ROW6, LOW);
  digitalWrite(ROW7, LOW);
  delay(500);
  // for 1
  digitalWrite(ROW3, HIGH);
  digitalWrite(ROW5, HIGH);
  theremin_sens();
  digitalWrite(ROW3, LOW);
  digitalWrite(ROW5, LOW);
  delay(500);
  // for 3
  digitalWrite(ROW2, HIGH);
  digitalWrite(ROW3, HIGH);
  digitalWrite(ROW4, HIGH);
  digitalWrite(ROW5, HIGH);
  digitalWrite(ROW6, HIGH);
  theremin_sens();
  digitalWrite(ROW2, LOW);
  digitalWrite(ROW3, LOW);
  digitalWrite(ROW4, LOW);
  digitalWrite(ROW5, LOW);
  digitalWrite(ROW6, LOW);
  delay(1000);
}
}
  }
  //If the button is not pressed, sets on the leds  <<< (it doesn’t work)
  // FAST FAST FAST FAST FAST FAST FAST FAST
  
  // for 1
  digitalWrite(ROW1, HIGH);
  theremin_sens2();
  digitalWrite(ROW1, LOW);
  // for 2
  digitalWrite(ROW2, HIGH);
  theremin_sens2();
  digitalWrite(ROW2, LOW);
  // for 3
  digitalWrite(ROW3, HIGH);
  theremin_sens2();
  digitalWrite(ROW3, LOW);
  // for 5
  digitalWrite(ROW5, HIGH);
  theremin_sens2();
  digitalWrite(ROW5, LOW);
  // for 6
  digitalWrite(ROW6, HIGH);
  theremin_sens2();
  digitalWrite(ROW6, LOW);
  // for 7
  digitalWrite(ROW7, HIGH);
  theremin_sens2();
  digitalWrite(ROW7, LOW);

  delay(10);
 
   // REAPEAT REAPEAT REAPEAT REAPEAT REAPEAT 
 
  // for 1
  digitalWrite(ROW1, HIGH);
  theremin_sens2();
  digitalWrite(ROW1, LOW);
  // for 2
  digitalWrite(ROW2, HIGH);
  theremin_sens2();
  digitalWrite(ROW2, LOW);
  // for 3
  digitalWrite(ROW3, HIGH);
  theremin_sens2();
  digitalWrite(ROW3, LOW);
  // for 4
  digitalWrite(ROW4, HIGH);
  theremin_sens2();
  digitalWrite(ROW4, LOW);
  // for 7
  digitalWrite(ROW7, HIGH);
  theremin_sens2();
  digitalWrite(ROW7, LOW);
  // for 6
  digitalWrite(ROW6, HIGH);
  theremin_sens2();
  digitalWrite(ROW6, LOW);
  // for 5
  digitalWrite(ROW5, HIGH);
  theremin_sens2();
  digitalWrite(ROW5, LOW);
}
}
int theremin_sens() {
for (i= 0; i <1000; i++) 
  {
  val = analogRead(PHOTOCELL);   	
// read photocell 
  f = factor * val - shift;     		
// this linearly maps the frequency to
                                                                       
 // a value between minfreq and maxfreq
                                                                        
// according to the calibration result
  normf = f / (double) minfreq;  	               
// Dividing an exponential function by the min value
  logf = log(normf) / log(gap); 		
// allows us to take the log (base gap) and the result 
  ilogf = round(logf);           	              
// is the number of notes above the lowest, once we round it.

 f = minfreq * pow(gap,ilogf);  	             
// we better "unlog" it.
    
  tone(PHONES, f);              	               
// this produces the tone signal

}
}

int theremin_sens2() {
for (i= 0; i <150; i++) 
  {
  val = analogRead(PHOTOCELL);   	
// read photocell 
  f = factor * val - shift;     		
// this linearly maps the frequency to
                                                                        
// a value between minfreq and maxfreq
                                                                      
// according to the calibration result
  normf = f / (double) minfreq;  	               
// Dividing an exponential function by the min value
  logf = log(normf) / log(gap); 		
// allows us to take the log (base gap) and the result 
  ilogf = round(logf);           	             
 // is the number of notes above the lowest, once we round it.
  f = minfreq * pow(gap,ilogf);  	             
// we better "unlog" it.
    
  tone(PHONES, f);              	              
 // this produces the tone signal
}
}

please help me…

The problem is that you are misunderstanding the purpose of an interrupt. An interrupt doesn't mean stop whatever it is doing and go do something else; it means temporarily stopping what it's doing, handling the interrupt and then going back to what it was doing. Like when you're cooking dinner and the doorbell rings.

You should take a look at the Blink Without Delay example for a way to write non-blocking code that can handle performing certain actions at certain times.