Quiz 2: Comments

Home

Comments

sketch is the name of a program file for the Arduino.  It is the code (such as the Blink example) that you compile and upload into the Arduino.

Read the following information from this useful Arduino guide on Sketches:

"The first few lines of the Blink sketch are a comment:

/*
  Blink
  The basic Arduino example.  Turns on an LED on for one second,
  then off for one second, and so on...  We use pin 13 because,
  depending on your Arduino board, it has either a built-in LED
  or a built-in resistor so that you need only an LED.
   
  http://www.arduino.cc/en/Tutorial/Blink
 */

Everything between the and */ is ignored by the Arduino when it runs the sketch.

It's there for people reading the code: to explain what the program does, how it works, or why it's written the way it is.

It's a good practice to comment your sketches, and to keep the comments up-to-date when you modify the code. This helps other people to learn from or modify your code.

There's another style for short, single-line comments. These start with // and continue to the end of the line. For example, in the line:

int ledPin = 13;                // LED connected to digital pin 13

the message "LED connected to digital pin 13" is a comment."

Commenting Out Code

Warning: Arduino is case sensitive so be careful with your capitals.

1. Open the Blink example sketch (refer to this guide if you need a refresher.)

2. Add two slash marks (//) to the start of the line with the pinMode statement (line of code) and upload the code again.  Observe what is different.  

2.1. With the modification you just made, does the LED turn on brightly or dimly?    

2.2. The symbols for a single-line comment are .

2.3 Note that you can also use CTRL+/ to comment/uncomment the line of code where your cursor is.  Try this now.


3. You have just commented out a line of codeComment out code rather than delete it if you think you may use the code again later.

4. Uncomment (delete the comment marks) to restore the missing line of code

4.1. Note
that you can also use CTRL+/ to comment/uncomment any lines of code you have selectedTry this now.

5. Upload
it and observe the results.

5.1. Based on your observations, the function to let an LED turn on full power instead of dimly in the Blink example is named (remember that Arduino is case sensitive).

6. Comment out the four lines inside of void loop() by using a multi-line comment (see above) and upload the code again.  Observe what is different.

6.1. Openmulti-line comment with the symbol and close it with the symbol

6.2. Based on your observations and reading the comments in the Blink example, the function to turn an LED on or off in the Blink example is named Turn the LED on by setting it Turn the LED off by setting it

In the Arduino programming environment, how do you insert comments?

  1. With two forward slashes //
  2. With two parenthesis ()
  3. With two curly braces {}
  4. With a matching pair of /* and */
  5. With CTRL+/ for lines you have selected or where your cursor is

Answer format: numbers separated by commas and spaces, like "2, 4" (not actual answer)

In the Arduino IDE (Integrated Development Environment), what is the purpose of using comments?

  1. For you or another programmer to understand what your code means.
  2. For the Arduino to understand what your code means.
  3. To temporarily remove a line of code from your program.

Answer format: numbers separated by commas and spaces, like "2, 4" (not actual answer)