Arduino Programming Structure
The programs you write using the Arduino C and its IDE are also called "sketches" in the Arduino literature.
The basic structure of Arduino programming language is fairly simple and runs in at least two parts. The two required parts, or functions, enclose blocks of statements. The two required functions are setup and loop. Setup is preparation block and Loop is execution Block. Both functions are required for program to work.
LED Blink program Try It View
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
The Setup Function:
A function present in every Arduino sketch. Run once before the loop() function. The setup() function should follow the declaration of any variables at the very beginning of the program. It is the first function to run in the program, is run only once, and is used to set pinMode or initialize serial communication.
The Loop Function:
A function present in every single Arduino sketch. After the setup() function completes its work, every Arduino C program automatically calls the loop()function. Loop includes the code to be executed continuously – reading inputs, triggering outputs etc.