Menu
CoddyTech

Comments in Your Sketch

Part of the First Circuits section of Coddy's Arduino journey. Lesson 6 of 22.

A comment is a note for people. The board skips it. Two slashes // turn the rest of the line into a comment:

digitalWrite(8, HIGH);  // red on

For a comment over several lines, start it with /* and end it with */:

/* Blink the red LED.
   It is on pin 8. */

Comments explain what the code is for, so you and others can read it later. They have a second use: put // in front of a line and the board ignores it, without you deleting it. This is called commenting out a line. Remove the // and the line is back.

To switch off an LED this way, comment out every line that uses its pin. A pin that was never made an output, but is still set HIGH, can make an LED glow faintly.

challenge icon

Challenge

Easy

The starter blinks a red LED (pin 8) and a yellow LED (pin 9) together. Make only the red one blink, without deleting any line:

  • comment out the three lines that use pin 9, with // or /* */
  • keep every line for pin 8 as it is

Press Run, then Check.

Try it yourself

/* Two LEDs blink together:
   red on pin 8, yellow on pin 9. */

void setup() {
  pinMode(8, OUTPUT);  // red
  pinMode(9, OUTPUT);  // yellow
}

void loop() {
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);
  delay(500);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  delay(500);
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in First Circuits

Practice on your own: Arduino playground