This is a common problem - you wait for available() to return non zero, then read more than one char.
This cannot work, every char you read must be guarded with a call to available(). Chars come in one by one and much much slower than your code runs.
You can either do this one-by-one:
for (byte x= 0; x < 2; x++)
{
while (!Serial.available())
{}
hrs[x] = Serial.read();
hrs[3] = 0; //null char
delay(10);
}
Or you can wait for enough chars to be available, then read them all:
while (Serial.available() < 2) // Stop and Wait for input
{}
for (byte x= 0; x < 2; x++)
{
hrs[x] = Serial.read();
hrs[3] = 0; //null char
delay(10);
}
The most elegant solution is to create a function that waits:
char wait_read ()
{
while (Serial.available () < 1)
{}
return Serial.read () ;
}
Then you've abstracted away all the details from you main code:
for (byte x= 0; x < 2; x++)
{
hrs[x] = wait_read();
hrs[3] = 0; //null char
delay(10);
}
By the way a while statement with an empty loop is really really hard to spot if you use just a semicolon - use braces and its obvious that the while isn't applying to the following code.