ARDUINO KROZ JEDNOSTAVNE PRIMJERE II izdanje
ZAGREB, 2014.
ARDUINO KROZ JEDNOSTAVNE PRIMJERE
Glavni i odgovorni urednik
Nakladnik
Za nakladnika
Recenzenti
Lektorica
ISBN 978-953-6091-41-6
UVOD
10 11 13 13 13 14 15
PRORADI
Prvi program
16 16 20 21
25
RGB diode
25 26 29 31 32 34 35 37 40 42 43 45 46 47 49 52
54
Reed
54 55 57 58 60 62 63 65 65 67 69 71 72
74 74 79
82
RGB diode
82 84 86 88 89 91 93 93 95 98 99 101
103 103 104 106 108
111 111 113 115 117 119 121 124 125 127 129
130 130 134
ZA KRAJ
139
-
-
-
13
UVOD
-
-
-
14
).
15
-
-
16
PRORADI
-
-
17 -
-
18 -
.
19
-
-
20
-
21 Prvi program -
22
/* Blink Turns on an LED on for one second, then off for one second, repeatedly. Most Arduinos have an on-board LED you can control. On the Uno and Leonardo, it is attached to digital pin 13. If you›re unsure what pin the on-board LED is connected to on your Arduino model, check the documentation at http://arduino.cc This example code is in the public domain.
by Scott Fitzgerald */
// the setup function runs once when you press reset or power the board void setup() { // initialize digital pin 13 as an output. pinMode(13, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay }
-
23
-
/* Blink Turns on an LED on for one second, then off for one second, repeatedly. Most Arduinos have an on-board LED you can control. On the Uno and Leonardo, it is attached to digital pin 13. If you›re unsure what pin the on-board LED is connected to on your Arduino model, check the documentation at http://arduino.cc This example code is in the public domain.
by Scott Fitzgerald */
// the setup function runs once when you press reset or power the board void setup() { // initialize digital pin 13 as an output. pinMode(13, OUTPUT); }
(
, .
24 -
// the loop function runs over and over again forever void loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay // wait for a second }
( ( -
-
25
-
-
26
-
27
int void setup() { pinMode(led, OUTPUT); digitalWrite(led, LOW); } void loop() { digitalWrite(led, HIGH); delay digitalWrite(led, LOW); delay }
//postavi led kao izlazni
28
-
29
-
-
30
int int void setup() { pinMode(led1, OUTPUT); pinMode OUTPUT); digitalWrite(led1, LOW); digitalWrite LOW); } void loop() { digitalWrite(led1, digitalWrite delay digitalWrite(led1, digitalWrite delay }
//postavi led1 kao izlazni
HIGH); HIGH); LOW); LOW);
-
-
31
-
int int void setup() { pinMode(led1, OUTPUT); pinMode OUTPUT); digitalWrite(led1, LOW); digitalWrite LOW); } void loop() { digitalWrite(led1, digitalWrite delay digitalWrite(led1, digitalWrite delay }
HIGH); LOW); LOW); HIGH);
//postavi izvod led1 kao izlazni
32
-
33
int int int void setup() { pinMode(led1, OUTPUT); pinMode OUTPUT); pinMode(led3, OUTPUT); digitalWrite(led1, LOW); digitalWrite LOW); digitalWrite(led3, LOW); } void loop() { digitalWrite(led1, delay digitalWrite(led1, digitalWrite delay digitalWrite digitalWrite(led3, delay digitalWrite(led3, }
//postavi izvod led1 kao izlazni //postavi izvod led3 kao izlazni
HIGH); LOW); HIGH); LOW); HIGH); LOW);
-
34
-
int int int void setup() { pinMode(led1, OUTPUT); pinMode OUTPUT); pinMode(led3, OUTPUT); digitalWrite(led1, HIGH); digitalWrite HIGH); digitalWrite(led3, HIGH); } void loop() { digitalWrite(led1, delay digitalWrite(led1, digitalWrite delay digitalWrite digitalWrite(led3, delay digitalWrite(led3, }
//postavi izvod led1 kao izlazni //postavi izvod led3 kao izlazni
LOW); HIGH); LOW); HIGH); LOW); HIGH);
-
35
36
int int ledZuta = 3; int void setup() { pinMode(ledCrvena, OUTPUT); pinMode(ledZuta, OUTPUT); pinMode(ledZelena, OUTPUT); digitalWrite(ledCrvena, LOW); digitalWrite(ledZuta, LOW); digitalWrite(ledZelena, LOW); }
//postavi izvod ledCrvena kao izlazni //postavi izvod ledZuta kao izlazni //postavi izvod ledZelena kao izlazni
void loop() { digitalWrite(ledCrvena, HIGH); delay digitalWrite(ledZuta, HIGH); delay digitalWrite(ledCrvena, LOW); digitalWrite(ledZuta, LOW); digitalWrite(ledZelena, HIGH); delay digitalWrite(ledZelena, LOW); digitalWrite(ledZuta, HIGH); delay digitalWrite(ledZuta, LOW); }
-
37
-
38
int int ledZuta = 3; int int ledCrvenaP = 5; int ledZelenaP = 6; void setup() { pinMode(ledCrvena, OUTPUT); pinMode(ledZuta, OUTPUT); pinMode(ledZelena, OUTPUT); pinMode(ledCrvenaP, OUTPUT); pinMode(ledZelenaP, OUTPUT); digitalWrite(ledCrvena, LOW); digitalWrite(ledZuta, LOW); digitalWrite(ledZelena, LOW); digitalWrite(ledCrvenaP, LOW); digitalWrite(ledZelenaP, LOW); } void loop() { digitalWrite(ledCrvena, HIGH); digitalWrite(ledZelenaP, HIGH); delay digitalWrite(ledZelenaP, LOW); digitalWrite(ledCrvenaP, HIGH); digitalWrite(ledZuta, HIGH); delay digitalWrite(ledCrvena, LOW); digitalWrite(ledZuta, LOW); digitalWrite(ledZelena, HIGH); delay digitalWrite(ledZelena, LOW); digitalWrite(ledZuta, HIGH); delay digitalWrite(ledZuta, LOW); digitalWrite(ledCrvenaP, LOW); }
//postavi //postavi //postavi //postavi //postavi
izvod izvod izvod izvod izvod
ledCrvena kao izlazni ledZuta kao izlazni ledZelena kao izlazni ledCrvenaP kao izlazni ledZelenaP kao izlazni
39 -
-
72
-
73
int int sklopka = 3; int void setup() { pinMode(led, OUTPUT); pinMode(sklopka, INPUT_PULLUP); pinMode(reed, INPUT_PULLUP); digitalWrite(led, LOW); }
//postavi izvod led kao izlazni //postavi izvod sklopka kao ulazni //postavi izvod reed kao ulazni
voidloop() { if(digitalRead(sklopka)==LOW&&digitalRead(reed)==LOW){ //i zatvoren prozor digitalWrite(led, HIGH); } else { digitalWrite(led, LOW); } }
-
74
-
-
75
76
int int int int int led5 = 6; int led6 = 7; int int tipkalo = 9; int void setup() { pinMode(led1, OUTPUT); //postavi pinMode OUTPUT); pinMode(led3, OUTPUT); //postavi pinMode OUTPUT); pinMode(led5, OUTPUT); //postavi pinMode(led6, OUTPUT); //postavi pinMode(led7, OUTPUT); //postavi pinMode(tipkalo, INPUT_PULLUP);//postavi } void digitalWrite(led1, digitalWrite digitalWrite(led3, digitalWrite digitalWrite(led5, digitalWrite(led6, digitalWrite(led7, }
LOW); LOW); LOW); LOW); LOW); LOW); LOW);
void loop() { if (digitalRead(tipkalo)==LOW){ if } } if
izvod led1 kao izlazni izvod led3 kao izlazni izvod izvod izvod izvod
led5 kao izlazni led6 kao izlazni led7 kao izlazni tipkalo kao ulazni
77
digitalWrite } elseif
HIGH);
digitalWrite(led1, HIGH); digitalWrite(led7, HIGH); } elseif digitalWrite(led3, HIGH); digitalWrite HIGH); digitalWrite(led5, HIGH); } elseif digitalWrite(led1, digitalWrite(led3, digitalWrite(led5, digitalWrite(led7, } elseif
HIGH); HIGH); HIGH); HIGH);
digitalWrite(led1, digitalWrite(led3, digitalWrite digitalWrite(led5, digitalWrite(led7, } elseif
HIGH); HIGH); HIGH); HIGH); HIGH);
digitalWrite(led1, digitalWrite digitalWrite(led3, digitalWrite(led5, digitalWrite(led6, digitalWrite(led7, } else {
HIGH); HIGH); HIGH); HIGH); HIGH); HIGH);
} }
-
78 . Nai-
void nazivprocedure() { popis svih naredbi u proceduri }
void digitalWrite(led1, digitalWrite digitalWrite(led3, digitalWrite digitalWrite(led5, digitalWrite(led6, digitalWrite(led7, }
LOW); LOW); LOW); LOW); LOW); LOW); LOW);
.
.
79
-
80
int int int int int int int int int int
segB = 3; segD = 5; segE = 6; segF = 7; reed1 = 9; reed3 = 11;
void digitalWrite(segA, digitalWrite(segB, digitalWrite(segC, digitalWrite(segD, digitalWrite(segE, digitalWrite(segF, digitalWrite(segG, }
LOW); LOW); LOW); LOW); LOW); LOW); LOW);
void setup() { pinMode(segA, OUTPUT); pinMode(segB, OUTPUT); pinMode(segC, OUTPUT); pinMode(segD, OUTPUT); pinMode(segE, OUTPUT); pinMode(segF, OUTPUT); pinMode(segG, OUTPUT); pinMode(reed1, INPUT_PULLUP); pinMode INPUT_PULLUP); pinMode(reed3, INPUT_PULLUP); digitalWrite(segA, LOW); digitalWrite(segB, LOW); digitalWrite(segC, LOW); digitalWrite(segD, LOW); digitalWrite(segE, LOW); digitalWrite(segF, LOW); digitalWrite(segG, LOW); }
//postavi //postavi //postavi //postavi //postavi //postavi //postavi //postavi
izvod izvod izvod izvod izvod izvod izvod izvod
segA kao izlazni segB kao izlazni segC kao izlazni segD kao izlazni segE kao izlazni segF kao izlazni segG kao izlazni reed1 kao ulazni
//postavi izvod reed3 kao ulazni
81 void loop() { if (digitalRead(reed1)==LOW){ digitalWrite(segA,HIGH); digitalWrite(segB,HIGH); digitalWrite(segE,HIGH); digitalWrite(segF,HIGH); digitalWrite(segG,HIGH); } elseif (digitalRead LOW){ digitalWrite(segB,HIGH); digitalWrite(segC,HIGH); } elseif (digitalRead(reed3)==LOW){ digitalWrite(segA,HIGH); digitalWrite(segB,HIGH); digitalWrite(segE,HIGH); digitalWrite(segD,HIGH); digitalWrite(segG,HIGH); } }
//prikaz //prikaz //prikaz //prikaz //prikaz
slova slova slova slova slova
P P P P P
ZA KRAJ -