User Manual
41
/
223
Single 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 MEGA2560 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); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
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.
You are now going to make your LED blink faster. As you might have guessed, the
key to this lies in changing the parameter in () for the 'delay' command.










