Arduino Program Structure
Arduino Program Structure
Arduino Program Structure
1) Syntax 1) Variables
3) Control
structures
4) Operators
Statement
• Ends with “;”
• Like a full stop at the end of a sentence in English
Block
• Enclosed by {}
• Has a name in front of first curly bracket
• Like a “paragraph”
Comments are ignored by the Arduino IDE.
http://2012books.lardbucket.org/books/management-principles-v1.0/s11-organizational-structure-and-c.html
void setup() {}
The setup block contains the “settings” and runs just once when:
- The Arduino is reset/restarted or turned on
- New sketch is uploaded
void loop() {}
The loop block contains the “main” code and runs continuously
until:
- The Arduino is turned off or reset/restarted
- New sketch is uploaded
Usually the code will be organized in 3 sections.
1. Variable declarations
2. Setup – everything you want to do once
3. Loop – everything you want to repeat
void setup() {
//some thing to do once
}
void loop() {
//insert some pattern to illustrate repeat
or looping
}
Control Flow is the order in which statements and blocks are
executed
Control Structures are bits of code that decide the control flow
1+1
Operator
Operators do something to values.
- Assignment (=)
- Arithmetic (+, -, *, /, %)
- Comparison (==, >, <, >=, <=, !=)
- Boolean (&&, ||, !)
Where do you look for
additional references?
Language Reference
https://www.arduino.cc/
en/Reference/HomePage