Introduction



The programming language used to program an Arduino is C.

Think of your sketches as a list of instructions to be carried out in the order that they are written down. The Arduino microcontroller can perform 16 million instructions per second
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13, LOW);
When writing code you need to deal with punctuation. This punctuation is referred to as the syntax of the language. Most programming langages require you to be precise about the syntax. Arduino is case sensitive and names of things can only be described in one word. That's why when you use digitalWrite() it uses camel case convention and is one word.

digitalWrite() is an example of a function and this function takes two arguments: the pin it is talking about and the state of that pin. These arguments are passed to the function when that function is called. The arguments or parameters must be enclosed in parentheses and separated by commas. If you only have one argument you don't need to use a comma.

Also note that every statement ends in a semi-colon.





Uploading

When you click on the Upload button the first step that occurs is compilation. This process takes the code you have written and translates it from a high level language to machine code, a binary language that the Arduino understands. When you compile or verify your code it is checked to make sure that it conforms to the rules of the C language.



Boilerplate code

Every sketch you write must have two functions or methods that you define:
  1. void setup()
  2. void loop()
void setup(){


}
void loop(){

}
There is no semi-colon after void setup() or void loop() because you are defining a function rather than calling it.

Curly braces and the code that appears inside them are referred to as blocks of code or code blocks.



Serial Monitor

The Serial Monitor is part of the Arduino IDE. You can access it by clicking on the Serial Monitor Icon. You can type a message in the Serial Monitor and that message will be set to the Arduino. Conversely, Arduino can send messages to the Serial Monitor. This is handy as it is a way for you to see what is going on. To get Arduino to write to the Serial Monitor:
int a=2, b=2,c;
void setup(){
Serial.begin(9600);
c=a+b;
}
void loop(){
Serial.println("hello");
delay(1000);
Serial.println(c);
delay(1000);
}
This one may be more useful:
int degC,degF;
void setup(){
Serial.begin(9600);
degC=20;
degF=degC*9/5+32;
Serial.println(degF);
}
void loop(){

}