Today I got my Arduino which is great. Board and software setup fine as well. I tried to write a sketch with serial data communication but even the simplest sketch did not work properly. The example below should just output the number of characters the user sends to the board. The board seems to receive data properly (LED flashes) but the output is always crap. Sometimes nothing happens, sometimes the result is wrong.
Is there still a problem with the code or do I have a problem with the hardware? Could somebody try the sketch on your computer.
Thanks in advance for any hint!
@ awol: You're right that was not too precise but it was already around midnight...
@Lefty
When I removed the Serial.flush I got into a permanent loop where my first entry got sent to the serial monitor over and over again until I entered a new number.
But after I included it into the if statement it worked fine. Now I have something I can build on.
Many Thanks !!!
Cielful
void loop() // run over and over again
{
if (Serial.available()>0) {
delay(500);
int numChar = Serial.available();
Serial.println("Test");
Serial.println(numChar);
numChar = 0;
Serial.flush();
}
}