Konstrukcijski zadatak iz predmeta Mikroupravljači, Božićna svjetla. Program koristi jedan NUCLEO-F072RB, tri LED diode(crvenu, žutu i zelenu), žice za spajanje, tri otpornika i eksperimentalnu ploču. Kada se priključi napajanje NUCLEO-u, sa pritiskom na USER gumb se uključuju LED diode, višestrukim pritiskom se mjenja kojim ritmom svjetle, nakon 10 sekundi radi zaštite se svjetla isključuju.

Dependencies:   led

https://os.mbed.com/media/uploads/asantek/konstrukcijski_mikroupravljaci_shema.jpg

Committer:
asantek
Date:
Mon Feb 22 16:40:06 2021 +0000
Revision:
0:cc3ff6b5fbce
Child:
1:cd07874dbf19
Prvi commit. Dodan projekt sa main-om, led.h i led.cpp file-om.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
asantek 0:cc3ff6b5fbce 1 #include "mbed.h"
asantek 0:cc3ff6b5fbce 2 #include "led.h"
asantek 0:cc3ff6b5fbce 3 Serial pc(USBTX, USBRX);
asantek 0:cc3ff6b5fbce 4 LED led1(D2);
asantek 0:cc3ff6b5fbce 5 LED led2(D3);
asantek 0:cc3ff6b5fbce 6 LED led3(D4);
asantek 0:cc3ff6b5fbce 7 Ticker flipper1;
asantek 0:cc3ff6b5fbce 8 Timer svjetla;
asantek 0:cc3ff6b5fbce 9 Timer debounce;
asantek 0:cc3ff6b5fbce 10 InterruptIn gumb(USER_BUTTON);
asantek 0:cc3ff6b5fbce 11 int x=0;
asantek 0:cc3ff6b5fbce 12 int i=0;
asantek 0:cc3ff6b5fbce 13 int t=0.2;
asantek 0:cc3ff6b5fbce 14 void pritisak()
asantek 0:cc3ff6b5fbce 15 {
asantek 0:cc3ff6b5fbce 16 if(debounce.read_ms()>200) {
asantek 0:cc3ff6b5fbce 17 x++;
asantek 0:cc3ff6b5fbce 18 }
asantek 0:cc3ff6b5fbce 19 debounce.reset();
asantek 0:cc3ff6b5fbce 20 }
asantek 0:cc3ff6b5fbce 21 int main()
asantek 0:cc3ff6b5fbce 22 {//Inicijalizacija LED-ica
asantek 0:cc3ff6b5fbce 23 led1.stanje(0);
asantek 0:cc3ff6b5fbce 24 led2.stanje(0);
asantek 0:cc3ff6b5fbce 25 led3.stanje(0);
asantek 0:cc3ff6b5fbce 26 debounce.start();
asantek 0:cc3ff6b5fbce 27 svjetla.reset();
asantek 0:cc3ff6b5fbce 28 gumb.rise(&pritisak);
asantek 0:cc3ff6b5fbce 29 svjetla.start();
asantek 0:cc3ff6b5fbce 30
asantek 0:cc3ff6b5fbce 31 while (true) {
asantek 0:cc3ff6b5fbce 32 if(svjetla.read_ms()>10000){
asantek 0:cc3ff6b5fbce 33 led1.stanje(0);
asantek 0:cc3ff6b5fbce 34 led2.stanje(0);
asantek 0:cc3ff6b5fbce 35 led3.stanje(0);
asantek 0:cc3ff6b5fbce 36 flipper1.detach();
asantek 0:cc3ff6b5fbce 37 }
asantek 0:cc3ff6b5fbce 38 else{
asantek 0:cc3ff6b5fbce 39 if(x==0){
asantek 0:cc3ff6b5fbce 40 led1.stanje(0);
asantek 0:cc3ff6b5fbce 41 led2.stanje(0);
asantek 0:cc3ff6b5fbce 42 led3.stanje(0);
asantek 0:cc3ff6b5fbce 43 }
asantek 0:cc3ff6b5fbce 44 if(x==1){
asantek 0:cc3ff6b5fbce 45 i++;
asantek 0:cc3ff6b5fbce 46 if(i==1){led1.stanje(1);led2.stanje(0);led3.stanje(0);}
asantek 0:cc3ff6b5fbce 47 if(i==2){led1.stanje(0);led2.stanje(1);led3.stanje(0);}
asantek 0:cc3ff6b5fbce 48 if(i==3){led1.stanje(0);led2.stanje(0);led3.stanje(1);}
asantek 0:cc3ff6b5fbce 49 if(i==4){i=0;}
asantek 0:cc3ff6b5fbce 50 wait(0.1);
asantek 0:cc3ff6b5fbce 51 }
asantek 0:cc3ff6b5fbce 52 if(x==2){
asantek 0:cc3ff6b5fbce 53 i++;
asantek 0:cc3ff6b5fbce 54 if(i==1){led1.stanje(1);led2.stanje(0);led3.stanje(0);}
asantek 0:cc3ff6b5fbce 55 if(i==2){led1.stanje(0);led2.stanje(1);led3.stanje(0);}
asantek 0:cc3ff6b5fbce 56 if(i==3){led1.stanje(0);led2.stanje(0);led3.stanje(1);}
asantek 0:cc3ff6b5fbce 57 if(i==4){i=0;}
asantek 0:cc3ff6b5fbce 58 wait(0.2);
asantek 0:cc3ff6b5fbce 59 }
asantek 0:cc3ff6b5fbce 60 if(x==3){
asantek 0:cc3ff6b5fbce 61 led1.stanje(1);led2.stanje(1);led3.stanje(1);
asantek 0:cc3ff6b5fbce 62 wait(0.2);
asantek 0:cc3ff6b5fbce 63 led1.stanje(0);led2.stanje(0);led3.stanje(0);
asantek 0:cc3ff6b5fbce 64 wait(0.2);
asantek 0:cc3ff6b5fbce 65 }
asantek 0:cc3ff6b5fbce 66 if(x==4){x=0;}
asantek 0:cc3ff6b5fbce 67 }
asantek 0:cc3ff6b5fbce 68 }
asantek 0:cc3ff6b5fbce 69 }
asantek 0:cc3ff6b5fbce 70