hello i am having troubble with my code (or tutorial code to be precise).
i have written it excaktly and tried several methods but still the arduino ignores the IF statment and just goes straight to blinking and spamming "Helloworld!" through the serial.
The trailing semi-colon is your problem. It is the only piece of code executed if the test is true.
Check out the Arduino reference for the syntax of the if command.
You must never call Serial.read() if you haven't perviously called Serial.available() to
check there is at least one character available to read.
You want something more like:
void loop()
{
if (Serial.available () > 0)
{
int val=Serial.read(); // val shouldn't be global, its local
if (val == 'F') // NO SEMICOLON HERE
{
...
}
}
...
thank you for the answers, could you point me somewhere i can read up on how to properly use the serial? since i am using a tutorial to learn and this is what it told me to do so i'm copycating while i learn how the code works.
Well after removing the ";" the code works perfectly, and it's easy to miss that small detail but still get a big unwanted result. need to keep my eyes more open when checking my code but i guess that will come efter some more experience and screaming with frustration at my collection och elektronik components a few times.
OK, that was a bit strong, but experience on these forums shows neophytes never
test the result of read() for -1, but many use available () - although not always
carefully enough.