unsigned long wait = 15000;
void setup() {
Serial.begin(9600);
}
void loop() {
uint8_t BytesIn[60];
size_t count;
Serial.setTimeout(wait);
Serial.print("Enter 10 bytes to serial or wait ");
Serial.print(wait / 1000);
Serial.println(" seconds");
count = Serial.readBytes(BytesIn, 10); // BLOCKS here
if (!count) {
Serial.println("Timed out with no characters sent");
TONC();
}
else if (count < 10) {
Serial.print("Timed out with ");
Serial.print(count);
Serial.println(" characters sent");
TOCS();
}
else {
Serial.println("10 characters sent");
CSOK();
}
}
void TONC() {
wait = 30000;
}
void TOCS() {
wait = 20000;
}
void CSOK() {
wait = 15000;
}