Session 1 · 75 min
What does a sketch do once, and what does it repeat?
setup() runs once after power-up or reset; loop() repeats. Variables. Serial.begin() and Serial.println(), and a Serial Monitor set to the same baud rate.
In the studio
Hands-on
In Meet the board, predict and then watch the model of setup() once and loop() repeating. On the real board, start from Bare Minimum: print a greeting in setup() and a count in loop(), upload, and watch how fast the lines arrive. Press RESET and note what you see. Then move the count's declaration inside loop(): predict first, then test.
Starting code: Bare Minimum, from File/Examples/01.Basics/BareMinimum: an empty setup() and loop().
Evidence to collect
A prediction and the real Serial Monitor lines, annotated: which line ran once, which repeated, and why the count inside loop() never grows.
- Predict
- Before uploading, write which line you expect to see once and which many times.
- Debug
- If the Serial Monitor shows nothing or garbled text, check its baud rate against Serial.begin() before changing the code.
- Reflect
- In your own words: what does the board do between two runs of loop()?
⚠ Adult checks before power-on: The board sits on a non-conductive surface; nothing is wired to D0 or D1, which carry the USB serial link; the Serial Monitor uses the baud rate in Serial.begin().
Works towards: Reading code, Serial debugging