Let's improve our previous sketch to make the output more readable and interactive.
Add int dt = 500; above void setup() to slow things down.
Add delay(dt); after your print line to pause between loops.
Upload and run your sketch.
// Lesson 1: Hello World!
int dt = 500; // delay time in milliseconds
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("Hello World!");
delay(dt);
}
IDE shows helpful error messages when something goes wrong:
// Lesson 1: Hello World!
int dt = 500;
String yourName;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Hello World!");
Serial.println("What is your name?");
delay(dt);
while (Serial.available() == 0) {}
yourName = Serial.readString();
Serial.print("Hello ");
Serial.println(yourName);
Serial.println("How are you?");
delay(dt);
}
Try changing the dt value, the baud rate, or the printed string to see what happens!