EasyManua.ls Logo

LAFVIN Obstacle Avoidance Smart Car Kit - Understanding the Blink Sketch Code

LAFVIN Obstacle Avoidance Smart Car Kit
80 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...
41/78
gle line comments start with // and everything up until the end of that line is considered a comment.
The first line of code is: int led = 13;
As the comment above it explains, this is giving a name to the pin that the LED is attached to. This is 13 on most Arduinos, including the
UNO and Leonardo.
Next, we have the 'setup' function. Again, as the comment says, this is executed when the reset button is pressed. It is also executed
whenever the board resets for any reason, such as power first being applied to it, or after a sketch has been uploaded.
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
Every Arduino sketch must have a 'setup' function, and the place where you might want to add instructions of your own is between the
{ and the }.
In this case, there is just one command there, which, as the comment states tells the Arduino board that we are going to use the LED pin
as an output.
It is also mandatory for a sketch to have a 'loop' function. Unlike the 'setup' function that only runs once, after a reset, the 'loop' function
will, after it has finished running its commands, immediately start again.
void loop() { digitalWrite(led, HIGH); delay(1000); digitalWrite(led, LOW);
delay(1000);
}
Inside the loop function, the commands first of all turn the LED pin on (HIGH), then 'delay' for 1000 milliseconds (1 second), then turn
the LED pin off and pause for another second.
// turn the LED on (HIGH is the voltage
level) // wait for a second