Arduino programs can be divided into: structure,values(variables and constants) and functions.
Structure comprises of: Control structures,Arithmetic operators,Comparison operators,Boolean operators,Bitwise operators,Compound operators,comments,etc
Variables comprises of: Constants like HIGH/LOW,true/false,input/output,integer constants,floating point constants
Data types like void,boolean,char,byte,int,string,word,long,double,array,etc
Data type conversion methods like char(),int(),byte(),word(),long(),float()
Functions comprises of: Digital I/O functions-pinMode(), digitalWrite(), digitalRead()
Analog I/O functions-analogReference, analogRead(), analogWrite()
Advanced I/O functions-tone(), noTone(), shiftOut(), shiftIn(), pulseIn()
Time functions-millis(), micros(), delay()
Math functions-min(),max(),abs(),map(),pow(),sqrt() and so on.
Arduino programs are written in C/C++, although users only need define two functions to make a runnable program:
setup() – a function run once at the start of a program that can initialize settings
loop() – a function called repeatedly until the board powers off
Example: To blink an LED
/*
Turns on an LED on for one second, then off for one second, repeatedly.
*/
void setup() {
// initialize the digital pin as an output.
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}