EasyManua.ls Logo

SunFounder 3in1 Kit - Page 75

Default Icon
351 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder 3in1 Kit
so don’t get yourself into trouble.
Curlybraces {}
{} is the main component of the Arduino programming language, and they must appear in pairs. A better programming
convention is to insert a structure that requires curly braces by typing the right curly brace directly after typing the left
curly brace, and then moving the cursor between the curly braces to insert the statement.
Commment //
Commment is the part of the sketch that the compiler ignores. They are usually used to tell others how the program
works.
If we write two adjacent slashes in a line of code, the compiler will ignore anything up to the end of the line.
If we create a new sketch, it comes with two comments, and if we remove these two comments, the sketch will not be
affected in any way.
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
Comment is very useful in programming, and several common uses are listed below.
Usage A: Tell yourself or others what this section of code does.
void setup() {
pinMode(13,OUTPUT); //Set pin 13 to output mode, it controls the onboard LED
}
void loop() {
digitalWrite(13,HIGH); // Activate the onboard LED by setting pin 13 high
delay(500); // Status quo for 500 ms
digitalWrite(13,LOW); // Turn off the onboard LED
delay(500);// Status quo for 500 ms
}
Usage B: Temporarily invalidate some statements (without deleting them) and uncomment them when you need
to use them, so you dont have to rewrite them. This is very useful when debugging code and trying to locate
program errors.
void setup() {
pinMode(13,OUTPUT);
// digitalWrite(13,HIGH);
// delay(1000);
// digitalWrite(13,LOW);
// delay(1000);
}
(continues on next page)
2.3. How to build an Arduino Project 71

Related product manuals