How to exit out of a timer interrupt (ISR(TIMER1_COMPA_vect)) I have a code here where I collect an array of data and do some data analysis with the data. The only thing I'm struggle with is how to exit the ISR after I am done running my code. I am using a pre-scalar of 256 and running the ISR once (1Hz)
const signed int numReadings = 21;
volatile int gauge0[numReadings];
volatile int gauge1[numReadings];
volatile int add[numReadings];
volatile int deltaGAUGE;
volatile int slopeADD;
volatile int mean;

const int A0_pin = PC0;
const int A1_pin = PC1;

const uint16_t t1_load = 0;
const uint16_t t1_comp = 62500;

void setup() {
 
  //Set A0 and A1 pins as inputs
  DDRC &amp;= ~(1 &lt;&lt; A0_pin);
  DDRC &amp;= ~(1 &lt;&lt; A1_pin);

  //Reset Timer1 Control Reg A
  TCCR1A = 0;

  //Set CTC mode
  TCCR1B &amp;= ~(1 &lt;&lt; WGM13);
  TCCR1B |= (1 &lt;&lt; WGM12);

  //Set to prescaler of 1024
  TCCR1B |= (1 &lt;&lt; CS12);
  TCCR1B &amp;= ~(1 &lt;&lt; CS11);
  TCCR1B &amp;= ~(1 &lt;&lt; CS10);

  //Reset Timer1 and set compare value
  TCNT1 = t1_load;
  OCR1A = t1_comp;

  //Enable Timer1 compare interrupt
  TIMSK1 = (1 &lt;&lt; OCIE1A);

  //Enable global interrupt
  sei();
  
       Serial.begin(9600);
       Serial.println(&quot; &quot;);
       Serial.println(&quot;START&quot;);
        Serial.println(&quot; &quot;);


}


ISR(TIMER1_COMPA_vect){

       Serial.println(&quot; &quot;);
        for (unsigned int i=0; i&lt;numReadings; i++)
            {
                        gauge0[i] = (analogRead(A0_pin))*(100.00/1024.0);
                        gauge1[i] = (analogRead(A1_pin))*(100.00/1024.0);
                        add[i] = ((gauge0[i]+gauge1[i]));
                
                        deltaGAUGE = abs(add[20] - add[0]);
                        slopeADD = abs((add[20]-add[0])/(20-0));
                        mean = (add[1]+add[2]+add[3]+add[4]+add[5]+add[6]+add[7]+add[8]+add[9]+add[10]+
                             
                     add[11]+add[12]+add[13]+add[14]+add[15]+add[16]+add[17]+add[18]+add[19]+add[20])/20;

                        if(i == 20)
                {     
                      Serial.print(&quot;This of the delta AVG reading: &quot;);
                      Serial.println(deltaGAUGE);
                      Serial.println(&quot; &quot;);
                      Serial.print(&quot;This of the slope reading: &quot;);
                      Serial.println(slopeADD);
                      Serial.println(&quot; &quot;);
                      Serial.print(&quot;This of the mean reading: &quot;);
                      Serial.println(mean);
                      Serial.println(&quot; &quot;);
                      Serial.println(&quot;END&quot;);    
              }
                        
                        delay(50); //wait .05 sec
                                
          }
 

}


void loop()
{

}




When I run the circuit, the interrupt keep executing every seconds for an infinite amount of time, while I just want it to run once and exit.
I have tried the exit(0) command but I get an output that looks like this
START
 
This of the delta AVG reading: 0
 
This of t


As you can see, The program does not execute completely. Anyone have any idea how I can fix this, or anyhow I can better my code? thank you.
As some of the comments have suggested, I would either get rid of the ISR or reduce the size significantly. When using ISRs, it is recommended that you keep the code as small as possible. Use it to set variables, for example
//these two variables are global
ISR(TIMER1_COMPA_vect){
    someValue = true;
    numberOfValues++;
}

you should also never use any Serial functions inside an ISR as these use interrupts themselves which can cause all kinds of problems
After using the ISR to update global variables, you can then use if() or while() statements within the loop() function to execute your serial print functions and such
P.S. on a side note, I would recommend changing your code where you calculated mean from
    mean = (add[1]+add[2]+add[3]+add[4]+add[5]+add[6]+add[7]+add[8]+add[9]+add[10]+         
add[11]+add[12]+add[13]+add[14]+add[15]+add[16]+add[17]+add[18]+add[19]+add[20])/20;

to
for(uint8_t i = 1;i&lt;=20;i++){
    mean += add[i];
}
mean /= 20;