Sie sind auf Seite 1von 15

Arduino Sketch

Structure Values Functions

1) Syntax 1) Variables

2) Main structure 2) Constants

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.

Multi-line comment: between /* … */


/*
I am a comment
I am a comment too!
*/

Single line comment: everything after //

// This whole line is a comment


digitalWrite(led, HIGH); // comment here
1. Open Arduino IDE
2. Go to File > Examples >
1.Basics > Blink
3. Delete all the comments
4. Identify the statements
and blocks
void setup() {
pinMode(13, OUTPUT);
Can you identify
}
the blocks and
statements in this
void loop() {
example?
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
void setup() {
led, OUTPUT); Observe that
} there are 2
Blocks.

void loop() { Recap:


Blocks are
enclosed by {}
}
void setup() {
pinMode(13, OUTPUT); Observe that
} there are 5
Statements.
void loop() {
digitalWrite(13, HIGH); Recap:
delay(1000); Statements end
digitalWrite(13, LOW); with “;”
delay(1000);
}
Structure refers to the parts and
organization of something.

The Arduino main structure refers to


the parts which MUST be present in
every sketch

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

Sequential Selection Iteration

Statement by Choosing which Repeating a


statement block to do block
Values

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

Das könnte Ihnen auch gefallen