I have written a relatively long sketch using Serial.println () that is based on a previous sketch that works perfectly. However, the newer sketch returns gibberish in most cases rather than the requested text. All of the problem spots are relatively basic as noted below. Am I missing some obvious solution to this problem?
I simply do not see any difference between the sketch that works and this one.
Baud rate was set at 9600. I have tried higher and lower rates and matched the serial monitor setting and the rate in the sketch. I have scoured the forums and can't find an obvious answer.
Thanks in advance. Sample from beginning and end the new sketch:
void loop()
{
//arduino waits for input
if (Serial.available() > 0);
{
char letter = Serial.read();
if (letter == 'a')
{
Serial.println ("stim series a. ON 125 ms; ISI 250 ms");
Serial.println ("TOP, MID, BOTTOM row, 3 sec between rows");
digitalWrite(ermPin4, HIGH);
delay(125);
digitalWrite(ermPin4, LOW);
delay (250);
// more code here
digitalWrite(ermPin11, HIGH);
delay(125);
digitalWrite(ermPin11, LOW);
delay (100);
Serial.println ("correct answer: DOWN");
digitalWrite (ledPin, HIGH);
delay (6000);
digitalWrite (ledPin, LOW);
delay (1000);
Serial.println ("* * *");
Serial.println ("Just ran series i");
Serial.println ("* * *");
Serial.println ("Waiting for input");
Serial.println ();
}
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.