You are missing the fundamental method of what you must do to receive a serial character inside your sketch. First you must always perform a test to make sure that there is a complete character ready to be read before you can read it:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
Note the testing for a character being avalible in the if statement before performing the Serial.read statement which will actually perform the reading of the character.
Further study of the Serial libraries function should help you also.
When the input buffer is empty is empty, read() will return a -1. That is not equal to '#' so it prints the number 'INVALID!'.
If you wanted a character string, use double quotes: "INVALID!"
If you want it to print "INVALID!" when the input does not match ANY of the choices you have to put 'else' after EACH 'if' statement, not just the last one. As written, any input that is not '#' will trigger the 'INVALID' message.
Since in this case you don't want to execute more than one of those code paths in any given loop, you can change all but the first "if" to an "else if". This will make the loop run faster because as soon as one of the conditions is met and the associated block is executed, program execution will jump back to the beginning of the loop instead of testing all the other conditions.
johnmchilton:
Since in this case you don't want to execute more than one of those code paths in any given loop, you can change all but the first "if" to an "else if". This will make the loop run faster because as soon as one of the conditions is met and the associated block is executed, program execution will jump back to the beginning of the loop instead of testing all the other conditions.
yeah, I thought about that...
but didn't really bother too much with it...
thanks you guys!
I'll post new issues as they come along...
hopefully my lazy mind will want to learn something from it...