Read a key only-once ?

I am using the phi_interfaces library to read a group of keys.

void loop() {

valid_Key = MyKey.getKey (); 

....
.....
......

if ( valid_Key == 'S' && key_Latch) {

key_Latch = 0;
set_RTC_gate = 1;

}

if (set_RTC_gate) set_TimeOfRTC();

delay(100); 

} 

//=====================

void set_TimeOfRTC() {

lcd.clear();
lcd.print("Entering clock setting!"):

delay(2000); 

if ( valid_Key == 'S' ) lcd.print( "Incrementing year");

(rest of code)

}

Now my problem is as soon as I press "S" key, the code enters the set_TimeOfRTC() function and also prints out the "Incrementing year" message after the "Entering clock setting" message + 2 sec delay..

I don't want this to happen like this . The "Incrementing year" message has to happen only on the second press of "S"

In other words after reading the first instance of "S", I need to flush it out prior to entering the next function ... any ideas ?

Use a counter variable.
First S increment the counter from 0 to 1
Second S and your counter = 1 you then print "Incrementing year"

Counter for key sense - yes that could be a workaround.

But I am more keen to know if there is a way to flush the variable from which the getKey() reads .. something like what happens with the Serial buffer - you read it and its gone !

I am more keen to know if there is a way to flush the variable from which the getKey() reads

Once you have tested it why not set it to another value that will not trigger any actions in your program.

if ( valid_Key == 'S' && key_Latch) 
{
  valid_Key = 'X';
  key_Latch = 0;
  set_RTC_gate = 1;
}

Once you have tested it why not set it to another value that will not trigger any actions in your program.

Absolutely. And why not ?? This IS the solution I wanted. Thanks Helibob !! :slight_smile: