The test sketch shown appears to have two flaws in the way it displays printed output on the serial monitor:
-
The first line of output is printed as if it's right justified, i.e. on the far right of the window.
-
When uploaded, it does not clear all previous output.
The first problem seems to be resolved by adding a 200 ms delay after the Serial.begin command.
But is that upload behaviour correct?
I usually run a sketch with Ctrl+u as a general rule, not just after a code edit. It's easier than pressing the UNO button, especially with many connector wires to a breadboard. It also catches any accidental code or circuit change I might have made.
Is there some simple fix I've missed? Otherwise guess I'll add 'Clear output' to my workflow.
// Some arbitrary constants
const int onPin = 9;
const int tOn = 100;
const int tOff = 900;
const int analogPin = A1;
// ... and variables
int period = tOn + tOff; // ms
int f = 1000 / period; // Frequency (Hz)
void setup() //
{
Serial.begin(9600);
// delay(200);
Serial.println("Test_Serial_Monitor_Printing");
Serial.print(F("tOn = "));
Serial.println(tOn);
Serial.print("tOff = ");
Serial.println(tOff);
Serial.print(F("period = "));
Serial.println(period);
Serial.print(F("f = "));
Serial.print(f);
Serial.println(F(" Hz"));
}
void loop()
{
}
// The sketch above displayed the following monitor output
// the first time it was uploaded.
// EDIT: Not sure why but cannot paste the rest of my comments. Will try again.
Gave up. Must be corrupted text. Here's an image instead.
