How to Comment In Arduino Progamming

Comment In Arduino

How to Comment In Arduino Progamming – In Arduino programming, we will get to know the term “Comment”.

Comments will often be used to explain the lines of the program that we make.

The C++ language that we use as the Arduino programming language, there are two types of Comments, namely Single-Lined or Multi-Line (Per-Block / multi-lined) comments.

How to Comment In Arduino Progamming

Single Line Comment Arduino

Line-by-line comments are preceded by two forward slashes “//”.

Any text after two slashes // to the end of that line will not be executed by the compiler.

Example:

//Use pin 13 for LED
int LED = 13;

//The setup() function will run for the first time only
void setup() {
  pinMode(LED, OUTPUT);    //iinitialize the LED pin as OUTPUT
}

//The loop() function will run the main program
void loop() {
  digitalWrite(LED, HIGH); //Turn On a LED
  delay(1000);             //wait 1 second
  digitalWrite(LED, LOW);  //Turn Off a LED
  delay(1000);             //wait 1 second
}

In the above program, we can see an explanation of each line of the program. This explanation will not process when Arduino is running. It only appears on the Arduino IDE software or text editor only.

Multi-Line / Per-Block Comments Arduino

Multi-line comments or often referred to as per-block comments are types of comments that require a longer explanation.

Multi-line comments start with “/” and end with “/”.

Text that is between /* and */ will not be processed by the compiler.

Example:

/* 
This is an example of an Arduino program that uses comments in
multi-lin.

It's very useful to explain things in detail related to
programs, such as:

* Rules
* steps
* Program Version
* Program Revision
* etc.

That's it.
*/

//Use pin 13 for LED
int LED = 13;

//The setup() function will run for the first time only
void setup() {
  pinMode(LED, OUTPUT);    //initialize the LED pin as OUTPUT
}

//The loop () function will run continuously and repeatedly
void loop() {
  digitalWrite(LED, HIGH); //Turn On LED
  delay(1000);             //wait 1 seconds
  digitalWrite(LED, LOW);  //Turn Off LED
  delay(1000);             //wait 1 seconds
}

Which is the best?

Both are the same. It depends on you who will use it.

Hopefully this article is useful.

Scroll to Top