Programming Structure

Overview

The Arduino software is open-source. The source code for the Java environment is released under the GPL and the C/C++ microcontroller libraries are under the LGPL.

Sketch − The first new terminology is the Arduino program called “sketch”.

Structure

The basic structure of the Arduino program is of very simple and runs in at least two parts . These two parts are void setup() and void loop(), both parts or functions are required for the working of the program which are enclosed in a statement.

     void setup()   // put your setup code here, to run once:
 {
   }
 void loop()        // put your main code here, to run repeatedly:

 }
 

where setup() is for the preparation and loop() is the execution.Both functions are required for the program to work.

The setup function should follw the declaration of any variables at the very beginning of the program.It is the first function to run the program,is run only once and is used to set pinMode or initialize serial communication.

The loop function follows next and includes the code to be executed continously-reading inputs,triggering outputs etc.This function is the core of all Arduino programs and does the bulk of the work

setup()

The setup() function is called once when your program starts.use it to initialize pinmodes or begin serial.It must be included in aprogram even if there are statements to run.

void setup()
{
pinMode(pin,OUTPUT);  // sets the pin as output
}

loop()

After calling the setup() function, the loop() functiondoes precisely what ist name suggest and loops consecuitvely,allowing the program to change,respond and control the Arduino board.

void loop()
{
digitalWrite(pin,HIGH); // set outpur of pin as high
}

Next : Variables