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:
Tue Feb 23 11:50:22 2021 +0000
Revision:
3:3c6cfb9e5bc9
Parent:
1:cd07874dbf19
sad

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 Timer svjetla;
asantek 0:cc3ff6b5fbce 8 Timer debounce;
asantek 0:cc3ff6b5fbce 9 InterruptIn gumb(USER_BUTTON);
asantek 0:cc3ff6b5fbce 10 int x=0;
asantek 0:cc3ff6b5fbce 11 int i=0;
asantek 0:cc3ff6b5fbce 12 void pritisak()
asantek 0:cc3ff6b5fbce 13 {
asantek 0:cc3ff6b5fbce 14 if(debounce.read_ms()>200) {
asantek 0:cc3ff6b5fbce 15 x++;
asantek 0:cc3ff6b5fbce 16 }
asantek 0:cc3ff6b5fbce 17 debounce.reset();
asantek 0:cc3ff6b5fbce 18 }
asantek 0:cc3ff6b5fbce 19 int main()
asantek 0:cc3ff6b5fbce 20 {//Inicijalizacija LED-ica
asantek 0:cc3ff6b5fbce 21 led1.stanje(0);
asantek 0:cc3ff6b5fbce 22 led2.stanje(0);
asantek 0:cc3ff6b5fbce 23 led3.stanje(0);
asantek 0:cc3ff6b5fbce 24 debounce.start();
asantek 0:cc3ff6b5fbce 25 svjetla.reset();
asantek 0:cc3ff6b5fbce 26 gumb.rise(&pritisak);
asantek 0:cc3ff6b5fbce 27 svjetla.start();
asantek 1:cd07874dbf19 28 //Beskonačna while petlja
asantek 0:cc3ff6b5fbce 29 while (true) {
asantek 1:cd07874dbf19 30 //Nakon 10 sekundi isključi LED svjetla
asantek 0:cc3ff6b5fbce 31 if(svjetla.read_ms()>10000){
asantek 0:cc3ff6b5fbce 32 led1.stanje(0);
asantek 0:cc3ff6b5fbce 33 led2.stanje(0);
asantek 0:cc3ff6b5fbce 34 led3.stanje(0);
asantek 0:cc3ff6b5fbce 35 }
asantek 0:cc3ff6b5fbce 36 else{
asantek 0:cc3ff6b5fbce 37 if(x==0){
asantek 0:cc3ff6b5fbce 38 led1.stanje(0);
asantek 0:cc3ff6b5fbce 39 led2.stanje(0);
asantek 0:cc3ff6b5fbce 40 led3.stanje(0);
asantek 0:cc3ff6b5fbce 41 }
asantek 0:cc3ff6b5fbce 42 if(x==1){
asantek 0:cc3ff6b5fbce 43 i++;
asantek 0:cc3ff6b5fbce 44 if(i==1){led1.stanje(1);led2.stanje(0);led3.stanje(0);}
asantek 0:cc3ff6b5fbce 45 if(i==2){led1.stanje(0);led2.stanje(1);led3.stanje(0);}
asantek 0:cc3ff6b5fbce 46 if(i==3){led1.stanje(0);led2.stanje(0);led3.stanje(1);}
asantek 0:cc3ff6b5fbce 47 if(i==4){i=0;}
asantek 0:cc3ff6b5fbce 48 wait(0.1);
asantek 0:cc3ff6b5fbce 49 }
asantek 0:cc3ff6b5fbce 50 if(x==2){
asantek 0:cc3ff6b5fbce 51 i++;
asantek 0:cc3ff6b5fbce 52 if(i==1){led1.stanje(1);led2.stanje(0);led3.stanje(0);}
asantek 0:cc3ff6b5fbce 53 if(i==2){led1.stanje(0);led2.stanje(1);led3.stanje(0);}
asantek 0:cc3ff6b5fbce 54 if(i==3){led1.stanje(0);led2.stanje(0);led3.stanje(1);}
asantek 0:cc3ff6b5fbce 55 if(i==4){i=0;}
asantek 0:cc3ff6b5fbce 56 wait(0.2);
asantek 0:cc3ff6b5fbce 57 }
asantek 0:cc3ff6b5fbce 58 if(x==3){
asantek 0:cc3ff6b5fbce 59 led1.stanje(1);led2.stanje(1);led3.stanje(1);
asantek 0:cc3ff6b5fbce 60 wait(0.2);
asantek 0:cc3ff6b5fbce 61 led1.stanje(0);led2.stanje(0);led3.stanje(0);
asantek 0:cc3ff6b5fbce 62 wait(0.2);
asantek 0:cc3ff6b5fbce 63 }
asantek 0:cc3ff6b5fbce 64 if(x==4){x=0;}
asantek 0:cc3ff6b5fbce 65 }
asantek 0:cc3ff6b5fbce 66 }
asantek 0:cc3ff6b5fbce 67 }
asantek 0:cc3ff6b5fbce 68