Project 1.01: Blink

Nearly everyone starts out by learning how to blink an LED. This project demonstrates all of the elements that we need to go on to bigger and better things: we set the pinMode in the setup() block and then blink LED1 by turning it on for one second and then off for one second. Upload this sketch to the Arno, wait a moment, and then watch LED1 blink!

Let’s take a closer look at how this sketch works. We declare one int type variable at the top of the sketch. It is a global variable since it is declared outside of the setup() block, loop() block, or any other function. This means we can use it anywhere else in the sketch. int LED1 = 13; Every sketch needs a setup() and loop() block. The setup() block runs only once. That’s all we need to set the pinMode of the LED to an output so that we can switch it on and off: void setup(){ pinMode(LED1,OUTPUT); } Now comes the loop() block. This block will run over and over again. At the top of the block comes the digitalWrite statement. This powers the pin attached to LED1 with 5 V, causing current to run from the pin, through the LED and resistor (we need that resistor to limit the current that will flow through the circuit), and finally to ground. This causes LED1 to light up. void loop(){ digitalWrite(LED1,HIGH); LED1 will remain in a HIGH state until we tell it otherwise or we disconnect the Arno from its power source. We want it to stay on for only a second so we wait a 1000 milliseconds: delay(1000); And then switch the pin to LOW. Now the pin is at the same voltage as ground. There’s no difference in electrical potential, so no current flows and the LED switches off: digitalWrite(LED1,LOW); We keep it off for another second and then finish the loop() block: delay(1000); } The closing bracket tells the Arno to go back to the top of the loop() block and do it all over again.