AutokeyReset function

Dear all,

I have 4 key operation. Test/Mute/ACK/RST. I am looking for sample code which could do this operation.

I Could able detect key pressed and print relevant printf statement.

Now i need modifcation code . when Test is pressed i wanted to started 1 min timer_interrupt. If any key is not pressed within 1 min it should print statement of RUN_RESET() & print statement once.once it print data it will go to normal condition.

How it can be done using timer interrupt.

#define TEST 3
#define RESET 4
#define ACK 5
#define MUTE 6
#define AUTO_RST 7

unsigned char Debounce = 0;
unsigned char Auto_Counter = 0;
struct {
  unsigned RUNMODE        : 1;
  unsigned PRGMODE        : 1;
  unsigned KeyLock_MUTE     : 1;
  unsigned KeyLock_ACK      : 1;
  unsigned KeyLock_RESET      : 1;
  unsigned KeyLock_TEST     : 1;
  unsigned KeyLock_MUTE1      : 1;
  unsigned KeyLock_ACK1     : 1;
  unsigned KeyLock_RESET1     : 1;

  unsigned KeyLock_TEST1      : 1;
  unsigned BLINKFLAG        : 1;
  unsigned BLINKFLAG1       : 1;
  unsigned FLASHFLAG        : 1;
  unsigned KeyTEST_PRESS      : 1;
  unsigned MANUAL_RESET     : 1;
  unsigned AUTO_RESET       : 1;


} bits;


void  RUN_TEST()
{

  Serial.println("Run Test function callled");

}


void RUN_RESET()
{
  Serial.println("Run Reset function callled");

}

void RUN_MUTE()
{
  Serial.println("Run MUTE function callled");
}

void RUN_ACK()
{
  Serial.println("Run ACK function callled");
}

//********************************************************************************************
//// CHECK IF TEST IS PRESSED
//********************************************************************************************

void Key_CHK_TEST() {

  if (!TEST && !bits.KeyLock_TEST1) {
    Debounce++;
    if (Debounce > 30) {
      Debounce = 0;
      bits.KeyLock_TEST1 = 1;
      RUN_TEST();

    }
  } else if (TEST && bits.KeyLock_TEST1) {
    bits.KeyLock_TEST1 = 0;
    Debounce = 0;
  }

}

//**********************************************************************************************
//// CHECK MUTE KEY pressed
//**********************************************************************************************

void Key_CHK_MUTE() {

  if (!MUTE && !bits.KeyLock_MUTE1) {
    Debounce++;
    if (Debounce > 30) {
      Debounce = 0;
      bits.KeyLock_MUTE1 = 1;
      RUN_MUTE();
    }
  } else if (MUTE && bits.KeyLock_MUTE1) {
    bits.KeyLock_MUTE1 = 0;
    Debounce = 0;
  }

}

//**********************************************************************************************
//// CHECK ACK KEY PRESS IN RUN MODE
//**********************************************************************************************
void Key_CHK_ACK() {
  if (!ACK && !bits.KeyLock_ACK1) { // CHECK IF ack IS PRESSED
    Debounce++;
    if (Debounce > 30) {
      Debounce = 0;
      bits.KeyLock_ACK1 = 1;
      RUN_ACK();
    }
  } else if (ACK && bits.KeyLock_ACK1) {
    bits.KeyLock_ACK1 = 0;
    Debounce = 0;
  }
}

//**********************************************************************************************
//// CHECK RESET KEY PRESS IN RUN MODE
//**********************************************************************************************

void Key_CHK_RESET() {

  if (!RESET && !bits.KeyLock_RESET1) { // CHECK IF SELECT IS PRESSED
    Debounce++;
    if (Debounce > 30) {
      Debounce = 0;
      bits.KeyLock_RESET1 = 1;
      RUN_RESET();
    }
  } else if (RESET && bits.KeyLock_RESET1) {
    bits.KeyLock_RESET1 = 0;
    Debounce = 0;
  }
}






void CHECK_SEQ(void) {
  if (AUTO_RST == 1) {
    bits.MANUAL_RESET = 1;
    bits.AUTO_RESET = 0;

  }

  if (AUTO_RST == 0) {
    bits.MANUAL_RESET = 0;
    bits.AUTO_RESET = 1;

  }

}




// the setup function runs once when you press reset or power the board
void setup() {

  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(7, INPUT);
  Serial.begin(9600);
  CHECK_SEQ();
}




void loop() {

  Key_CHK_TEST();
  Key_CHK_MUTE();
  Key_CHK_ACK();
  if (bits.MANUAL_RESET == 1)
    Key_CHK_RESET();
  if (bits.AUTO_RESET == 1) {
    Auto_Counter++;
    if (Auto_Counter >= 100) {
      Auto_Counter = 0;
      RUN_RESET();

    }

  }
  delay(1000);
}

First, Hardware Timers are way, way above my experience level.
But if I understand your question, I would just use millis() in my loop function, and not a delay(1000).

Read the sticky at the top of the forum: Using millis() for timing. A beginners guide. (I disagree that it’s a beginners guide, but it is written so well that beginners can grasp the concept).