Structure of Arduino
THE SKETCH(arduino program)
An arduino program frequently known as SKETCH is composed of two functions
setup()
The setup() function is normally called when the sketch begins.
It usually used to initialize pin modes and variables
Example
1
2
3
4
5
6
7
8
9
10
|
int buttonPin = 3;
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
void loop() {
// ...
}
|
loop()
The loop function loops through the code consectutively allowing the program to adapt and change
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
int buttonPin = 3;
// setup initializes serial and the button pin
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
// loop checks the button pin each time,
// and will send serial if it is pressed
void loop() {
if (digitalRead(buttonPin) == HIGH) {
Serial.write('H');
}
else {
Serial.write('L');
}
delay(1000);
}
|