I've checked the carefully laid instructions for printing to Serial Monitor from setup(), but they don't work for me. I mean these instructions: http://arduino.cc/en/Guide/ArduinoLeonardoMicro?from=Guide.ArduinoLeonardo#toc4
int i = 0;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// Print to Serial Montor from setup().
Serial.println("Hello from setup()");
}
void loop() {
// wait for Serial Monitor to connect.
while (!Serial) {};
// once Serial Monitor connects, print 10 times.
while (i < 10) {
Serial.println("Hello from loop()");
i = i + 1;
}
}
Each time Leonardo is disconnected, it takes me few seconds to click on IDE menu items and open the Serial Montor. Whenever I do that, Serial Monitor is empty. But, the above code should be sitting doing nothing, until S.M. opens up?
I tried this code on Mega and it works as desired.
So, while (!Serial) {} doesn't work on Leonardo?