Matija Vučina Juraj Meštrović
Dependencies: mbed
main.cpp@1:f16f1d69b376, 2015-06-12 (annotated)
- Committer:
- mvucina
- Date:
- Fri Jun 12 17:26:12 2015 +0000
- Revision:
- 1:f16f1d69b376
- Parent:
- 0:61f6dae447a3
Zadatak 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mvucina | 1:f16f1d69b376 | 1 | /* |
mvucina | 1:f16f1d69b376 | 2 | Zadatak 1 Vu metar sa 20 LED elemenata. |
mvucina | 1:f16f1d69b376 | 3 | 2 LED stripa svaki s 10 LED. 2 funkcije: pojedinačna LED, Rastuci niz LED |
mvucina | 1:f16f1d69b376 | 4 | Matija Vučina & Juraj Meštrović |
mvucina | 1:f16f1d69b376 | 5 | */ |
mvucina | 0:61f6dae447a3 | 6 | #include "mbed.h" |
mvucina | 0:61f6dae447a3 | 7 | |
mvucina | 0:61f6dae447a3 | 8 | BusOut LedStrip(p14,p13,p12,p11,p10,p9,p8,p7,p6,p5); |
mvucina | 0:61f6dae447a3 | 9 | DigitalOut Strip1(p21); |
mvucina | 0:61f6dae447a3 | 10 | DigitalOut Strip2(p22); |
mvucina | 0:61f6dae447a3 | 11 | DigitalIn Din(p28); |
mvucina | 1:f16f1d69b376 | 12 | AnalogIn Ain(p20); // analogni ulaz izmedu 0.0 i 1.0 |
mvucina | 0:61f6dae447a3 | 13 | |
mvucina | 0:61f6dae447a3 | 14 | void VuRastuci (float analog); |
mvucina | 0:61f6dae447a3 | 15 | void VuPojedinacno (float analog); |
mvucina | 0:61f6dae447a3 | 16 | |
mvucina | 1:f16f1d69b376 | 17 | int main() |
mvucina | 1:f16f1d69b376 | 18 | { |
mvucina | 0:61f6dae447a3 | 19 | Din.mode(PullUp); |
mvucina | 0:61f6dae447a3 | 20 | Strip1=0; |
mvucina | 0:61f6dae447a3 | 21 | Strip2=0; |
mvucina | 0:61f6dae447a3 | 22 | |
mvucina | 0:61f6dae447a3 | 23 | while(1) { |
mvucina | 1:f16f1d69b376 | 24 | while(Din==1) { |
mvucina | 1:f16f1d69b376 | 25 | VuPojedinacno(Ain); //pojedinacno |
mvucina | 0:61f6dae447a3 | 26 | } |
mvucina | 0:61f6dae447a3 | 27 | |
mvucina | 1:f16f1d69b376 | 28 | while (Din==0) { |
mvucina | 1:f16f1d69b376 | 29 | VuRastuci(Ain); //rastuce |
mvucina | 0:61f6dae447a3 | 30 | } |
mvucina | 0:61f6dae447a3 | 31 | } |
mvucina | 0:61f6dae447a3 | 32 | } |
mvucina | 0:61f6dae447a3 | 33 | |
mvucina | 0:61f6dae447a3 | 34 | |
mvucina | 0:61f6dae447a3 | 35 | void VuRastuci (float analog) |
mvucina | 0:61f6dae447a3 | 36 | { |
mvucina | 0:61f6dae447a3 | 37 | Strip1=0; |
mvucina | 0:61f6dae447a3 | 38 | Strip2=0; |
mvucina | 0:61f6dae447a3 | 39 | LedStrip = 0x0; |
mvucina | 0:61f6dae447a3 | 40 | |
mvucina | 1:f16f1d69b376 | 41 | int x = (analog*20); |
mvucina | 1:f16f1d69b376 | 42 | LedStrip = ~(0x3FF<<x); //upali odgovarajuce izlaze |
mvucina | 1:f16f1d69b376 | 43 | Strip1=1; //upali prvu strip |
mvucina | 0:61f6dae447a3 | 44 | wait(0.01); |
mvucina | 1:f16f1d69b376 | 45 | |
mvucina | 1:f16f1d69b376 | 46 | Strip1=0; //ugasi prvi strip |
mvucina | 1:f16f1d69b376 | 47 | LedStrip = 0x0; //reset izlaza |
mvucina | 0:61f6dae447a3 | 48 | |
mvucina | 1:f16f1d69b376 | 49 | if(x>10) { |
mvucina | 1:f16f1d69b376 | 50 | x=x-10; |
mvucina | 1:f16f1d69b376 | 51 | LedStrip = ~(0x3FF<<x); //isti postupak samo za drugi strip |
mvucina | 1:f16f1d69b376 | 52 | Strip2=1; |
mvucina | 1:f16f1d69b376 | 53 | wait(0.01); |
mvucina | 1:f16f1d69b376 | 54 | } |
mvucina | 0:61f6dae447a3 | 55 | } |
mvucina | 0:61f6dae447a3 | 56 | |
mvucina | 0:61f6dae447a3 | 57 | void VuPojedinacno (float analog) |
mvucina | 0:61f6dae447a3 | 58 | { |
mvucina | 1:f16f1d69b376 | 59 | |
mvucina | 1:f16f1d69b376 | 60 | Strip1=0; |
mvucina | 1:f16f1d69b376 | 61 | Strip2=0; |
mvucina | 1:f16f1d69b376 | 62 | |
mvucina | 1:f16f1d69b376 | 63 | int x = (analog*20); |
mvucina | 1:f16f1d69b376 | 64 | |
mvucina | 1:f16f1d69b376 | 65 | if(x>0 && x<=10) { // ako je izmedu 0 i 10 to je prvi led strip |
mvucina | 1:f16f1d69b376 | 66 | LedStrip = 0x1<<(x-1); // upali prvi bit i pomakni ga na odgovarajuce mjesto |
mvucina | 1:f16f1d69b376 | 67 | Strip1=1; //upali strip 1 |
mvucina | 1:f16f1d69b376 | 68 | wait(0.01); |
mvucina | 1:f16f1d69b376 | 69 | Strip1=0; //ugasi strip 1 |
mvucina | 0:61f6dae447a3 | 70 | } else if(x>10 && x<=20) { |
mvucina | 1:f16f1d69b376 | 71 | LedStrip = 0x1<<(x-11); |
mvucina | 1:f16f1d69b376 | 72 | Strip2=1; //upali strip 2 |
mvucina | 1:f16f1d69b376 | 73 | wait(0.01); |
mvucina | 1:f16f1d69b376 | 74 | Strip2=0; //ugasi strip 2 |
mvucina | 0:61f6dae447a3 | 75 | } else { |
mvucina | 0:61f6dae447a3 | 76 | Strip1=0; |
mvucina | 0:61f6dae447a3 | 77 | Strip2=0; |
mvucina | 0:61f6dae447a3 | 78 | } |
mvucina | 1:f16f1d69b376 | 79 | } |