typestar

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

  1. Serial.begin(9600) opens the port; the monitor must match.
  2. print and println differ by the newline.
  3. millis() / 1000 turns the uptime clock into seconds.

Keywords and builtins used here

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.

Type this snippet

Step 2 of 3 in The sketch, step 2 of 27 in Language basics.

← Previous Next →