Arduino Comments
Comments are lines in Arduino sketch which help users to understand about how the program works. Comments can be either used for self-understanding or for the others to help them learn code instructions. Commenting is like disabling some lines of Arduino code.
Here are two ways to comment Arduino code:
We will use the LED blink example to help you to understand all three ways.
1. Using Forward Slash
Forward slash is the most common and frequently used way of commenting out lines in Arduino IDE. Using forward slash, we can also temporarily turn off Arduino code lines. Two forward slashes are used at the start of the line which we want to disable. Once the double forward slash will use that complete line it will change its color to gray indicating the commented line. Here is an example which shows a commented line.
Shortcut: This can also be done by first selecting the line which we want to comment and then press “Ctrl+ /”.
Another way of doing the same thing is using IDE “Edit” settings. First select the line to comment then go to edit and click comment/uncomment.
2. Multiline Comments
Previous forward slash method has one shortcoming that it cannot comment out multiple two or three lines; it’s only limited to one line per double forward slash comment. However, there is another way of doing this by using the multiline comment option.
For multiline comments use both forward slash and asterisk sign together. We have to add this in both start of comment and at the end unlike single line comments which only need to be written at first. Following is the syntax for writing multiline comments.
Code will
Be written here */
Note: Multiline comments have no shortcut in Arduino IDE.
Conclusion
Comments are lines of code which help to understand code easily. Here this guide covers two different ways of commenting Arduino code lines in IDE. Double forward slash is the common way of commenting Arduino code however for multiline comment we can use the second method. Also don’t forget the shortcut key Ctrl+/ for commenting.