Hello:
Would appreciate in help in coding the below code to introduce a "pause" when there is a serial.read. The project involves a remote control and sensor board that outputs various codes that can be captured and utilized. Each keyed output has a 0x20 header followed by a byte that can be used. in my case I am using it in a switch statement to call various routines.
If a user clicks multiple times on a key the input is read and multiple calls are made to my functions. I want the processing of a function to finish before the second click of a button takes place. Not sure if I need to throw out the serial reads or modify the functions. Unfortunately the remote code doesn't send a end of line or return code.
So what happens if I repeatedly press the key to increment on the remote the function is called incrementing a counter and displaying the new value on the 7 seg for 4 seconds before turning off. But it repeats itself. I want the function to finish processing before a new keypress is acknowledged
void loop() {
if (Serial.available() > 0) { // is a character available?
incomingByte = Serial.read(); // get the character
// check if a number was received
if (incomingByte!=0x20) { // Throw out character header 32
Serial.println(incomingByte);
switch (incomingByte) {
case 28:
Serial.println("Power");
break;
case 16:
Serial.println("Show Fan");
ToggleFan();
break;
case 17:
Serial.println("Show temp");
ShowTemp();
break;
case 25:
Serial.println("Show Eeprom");
ShowEeprom();
break;
case 24:
Serial.println("Increment");
Increment();
break;
case 21:
Serial.println("Decrement");
Decrement();
break;
default:
Serial.println(incomingByte);
}
}
}
void Decrement()
{
unsigned long start = millis();
unsigned long finish = start;
unsigned long counter;
if(storedTemp>=MIN_THERMOSTAT){
storedTemp--;
EEPROM.write(EEPROM_THERMOSTAT_ADDRESS,storedTemp);
Serial.println(storedTemp, DEC);
}
sevseg.setNumber((byte)storedTemp, 1);
while ((finish - start) <=5000) // do this loop for 5 seconds to display the sevseg
{
sevseg.refreshDisplay(); // Must run repeatedly
counter = counter+1;
finish = millis();
}
}