Consider the following Arduino sketch. What will be printed to the Serial Monitor?
void setup() {
Serial.begin(9600);
Serial.println("Start");
}
void loop() {
Serial.println("Looping");
delay(1000);
while(true) {}
}Think about what the while(true) {} does inside loop().
The setup() runs once and prints "Start". The loop() runs once, prints "Looping", then hits an infinite while(true) which stops further looping. So only "Start" and one "Looping" print.
In an Arduino sketch, which function is guaranteed to run only once after the board resets?
Think about the function that prepares the board before repeating actions.
The setup() function runs once after reset to initialize settings. The loop() runs repeatedly.
Examine the sketch below. Why does it fail to compile?
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Hello");
delay(1000);
}Check punctuation carefully in setup().
The line Serial.begin(9600) is missing a semicolon at the end, causing a syntax error.
Which of the following sketches has the correct minimal structure to compile and run?
Remember the two main functions every Arduino sketch needs.
An Arduino sketch must have both setup() and loop() functions. Option D has both, so it is correct.
Given the sketch below, how many times will "Tick" be printed to the Serial Monitor in 5 seconds?
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Tick");
delay(1000);
}Think about how long each loop cycle takes and how many fit in 5 seconds.
Each loop prints "Tick" then waits 1 second. In 5 seconds, it will print 5 times.
