So the task is to blink the LED multiple times depending on the what button is pressed e.g. if we press the sw3, the led has to blink for 3 seconds with an interrupt generating every 1/4th of a second.
Is there any way of activating the timer, if any of the buttons is pressed? and the buttons shouldn't be read as long as the timer is running?
I have wrote following code but i am not sure if it would work in the lab, so it would be great if any of you could help. Would appreciate a lot. Thank you.
    #include <avr/io.h>
    #include <avr/interrupt.h>
    #define LEDs PORTB
    #define KEYs PORTA
    #define OUTPUT 0b11111111
    #define INPUT  0b00000000
    volatile uint8_t count = 0;
    volatile uint8_t ready = 0;
    volatile uint8_t seconds;
    void set_up_the_timer(void);
    void blink_or_flash(void);
    int main(void)
    {
      DDRA = INPUT;
      DDRB = OUTPUT;
      LEDs = 0xFF;
      if(!(PINA & (1 << PINA0))) {
        set_up_the_timer();
        sei(); 
       }
      while (1) 
     {
        switch(KEYs) {
          case 0b11111110:
            seconds = 7;                                        // 0.15 * 7 = 1.05s
            blink_or_flash();
            break;
          case 0b11111101:
            seconds = 13;                                       // 0.15 * 13 = 1.95s;
            blink_or_flash();
            break;
          case 0b11111011:
            seconds = 20;                                       // 0.15 * 20 = 3s;
            blink_or_flash();
            break;
          case 0b11110111:
            seconds = 27;                                       // 0.15 * 27 = 4.05s
            blink_or_flash();
            break;
          case 0b11101111:
            seconds = 33;                                       // 0.15 * 33 = 4.95s
            blink_or_flash();
            break;
          case 0b11011111:
            seconds = 40;                                       // 0.15 * 40 = 60s
            blink_or_flash();
            break;
          case 0b10111111:
            seconds = 47;                                       // 0.15 * 47 = 7.05s
            blink_or_flash();
            break;
          case 0b01111111:
            seconds = 53;                                       // 0.15 * 53 = 7.95s
            blink_or_flash();
            break;  
          default:
            break;
        }
    }
 }
   void set_up_the_timer() {
        TCCR1A |= (1 << WGM12);
        OCR1A = 2344;                               // an interrupt occurring every 0.15 second
   
        TIMSK1 |= (1 << OCIE1A);
        TCCR1B |= (1 << CS12) | (1 << CS10);
  }
    void blink_or_flash() {
        if(ready == 1) {
            LEDs = 0x00;
            count = 0;
     }
   }
    ISR(TIMER0_COMPA_vect) {
       count++;
       LEDs = ~(LEDs);
       if(count >= seconds) {
       ready = 1;
       }
    }
    
 
                        
I´m not sure if my interpreation of your question is correct but maybe this helps: