1.5 Code Blink 2

Now lets take a look at the statements in the Blink code. The statements all end with “;”
[code lang="arduino" firstline="8" gutter="0"]
void setup() {
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
[/code]

pinMode(13, OUTPUT);

The first statement is pinMode. When the Arduino reads this statement it changes what job a pin has. In this case we are telling pin 13 to be an OUTPUT pin. An output pin effects the flow electricity. It is like a switch that can be connected to power or ground whenever the Arduino says.

digitalWrite(13, LOW);

Next we have digitalWrite. This tells the Arduino to connect an output pin to either power or ground. As with the previous statement, we need to give some information when we send the command. In this case, pin 13 and HIGH. HIGH means power and LOW means ground. When we created our circuit on the breadboard we connected Pin 13 to ground through our LED circuit. When we tell the Arduino to make pin 13 HIGH, power can flow to ground through the LED circuit. When pin 13 is LOW both ends of the LED circuit are connected to ground so electricity does not flow.

delay(1000);

To wait and not do anything else for a certain amount of time. In this case, to wait 1000 milliseconds. Which is 1 second.

If we were to write this code in plain english it would look something like this:

Setup:
Make pin 13 an output.

Loop:
Connect pin 13 to power.
Wait one second.
Connect pin 13 to ground.
Wait one second.

Any part of the code that is written in orange is part of the Arduino language so you can look up in the Arduino Language Reference.

Continue on to the next section to test your knowledge.

Leave a Reply