Serial output in Arduino
The sketch's voice: begin at a baud rate, print lines.
// Serial is the sketch's voice; the monitor listens at the same baud.
void setup() {
Serial.begin(9600);
Serial.println("Greenhouse controller v1");
}
void loop() {
Serial.print("Uptime seconds: ");
Serial.println(millis() / 1000);
delay(1000);
}
How it works
Serial.begin(9600)opens the port; the monitor must match.printandprintlndiffer by the newline.millis() / 1000turns the uptime clock into seconds.
Keywords and builtins used here
Serialbegindelayloopmillisprintprintlnsetupvoid
The run, in numbers
- Lines
- 11
- Characters to type
- 248
- Tokens
- 54
- Three-star pace
- 70 tpm
At the three-star pace of 70 tokens a minute, this run takes about 46 seconds.
Step 2 of 3 in The sketch, step 2 of 27 in Language basics.