Examples

From robotics

Arduino Examples

The examples are wonderful for beginners and are simple to find, easy to use, and reasonably well documented. The Examples home can be found at the Arduino examples page

With or without an Arduino board, open the Arduino software then navigate to

File->Examples->Basic->Bare Minimum

within the Arduino window.

This is the smallest amount of code that an Arduino program needs to Verify (compile). Press the Verify button (checkmark in the upper left hand corner of the screen) to Verify this code.

When a program is compiled it is linked to libraries and processed into machine specific code that can be run by the processor. In Arduino, code is processed into a .hex file containing the machine code to configure and run the AVR proccessor on the board. Most systems utilize the command line tool “MAKE” to compile programs. Although you do not need to understand Make, it is a very essential part of most programs and is used by the Arduino IDE.

Blink

Int led =13 ; 

Starts an int type variable named led and makes its value equal to 13.

pinMode(led, OUTPUT); 

PinMode is used to initialize a pin as an input or output. The first parameter is the pin number. The variable led is equal to 13. This will make pin 13 and output.

pinMode(switch,INPUT_PULLUP);

INPUT_PULLUP initializes the switch pin as an input with a pull-up resistor. This means the pin will be high when disconnected and only becomes low when you connect the pin to ground. The internal pull-up circuit is ideal for the micro controllers power requirements.

digitalWrite(led, HIGH); 

DigitalWrite is used to change the state of a digital output between high and low, or 1 and 0.

delay(1000); 

The delay function halts the program until the time interval is met. Certain functions such as timers or interrupts will continue to run during the delay. The time is in milliseconds. 1000 milliseconds = 1 second.