MU_konstrukcijski zadatak_VD
Dependencies: mbed MU_upravljanje_raskrzjem
main.cpp@1:4886daf51d91, 2020-11-25 (annotated)
- Committer:
- Vdavidovi
- Date:
- Wed Nov 25 17:15:14 2020 +0000
- Revision:
- 1:4886daf51d91
- Parent:
- 0:13a153863b69
Upravljanje raskrzjem
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vdavidovi | 0:13a153863b69 | 1 | #include "mbed.h" |
Vdavidovi | 0:13a153863b69 | 2 | #include "MU_upravljanje_raskrzjem.h" |
Vdavidovi | 0:13a153863b69 | 3 | |
Vdavidovi | 0:13a153863b69 | 4 | Traffic vcrvena1 (p5); |
Vdavidovi | 0:13a153863b69 | 5 | Traffic vzuta1 (p6); |
Vdavidovi | 0:13a153863b69 | 6 | Traffic vzelena1 (p7); |
Vdavidovi | 0:13a153863b69 | 7 | Traffic mcrvena1 (p8); |
Vdavidovi | 0:13a153863b69 | 8 | Traffic mzelena1 (p9); |
Vdavidovi | 0:13a153863b69 | 9 | |
Vdavidovi | 0:13a153863b69 | 10 | Traffic vcrvena2 (p30); |
Vdavidovi | 0:13a153863b69 | 11 | Traffic vzuta2 (p29); |
Vdavidovi | 0:13a153863b69 | 12 | Traffic vzelena2 (p28); |
Vdavidovi | 0:13a153863b69 | 13 | Traffic mcrvena2 (p27); |
Vdavidovi | 0:13a153863b69 | 14 | Traffic mzelena2 (p26); |
Vdavidovi | 0:13a153863b69 | 15 | |
Vdavidovi | 0:13a153863b69 | 16 | InterruptIn tipkalo(p18); |
Vdavidovi | 0:13a153863b69 | 17 | |
Vdavidovi | 0:13a153863b69 | 18 | Ticker tik1; |
Vdavidovi | 0:13a153863b69 | 19 | |
Vdavidovi | 0:13a153863b69 | 20 | int t=0,p=0; |
Vdavidovi | 0:13a153863b69 | 21 | |
Vdavidovi | 0:13a153863b69 | 22 | void tiker1() |
Vdavidovi | 0:13a153863b69 | 23 | { |
Vdavidovi | 0:13a153863b69 | 24 | t=t+1; |
Vdavidovi | 0:13a153863b69 | 25 | } |
Vdavidovi | 0:13a153863b69 | 26 | |
Vdavidovi | 0:13a153863b69 | 27 | void pjesaci() |
Vdavidovi | 0:13a153863b69 | 28 | { |
Vdavidovi | 0:13a153863b69 | 29 | p=1; |
Vdavidovi | 0:13a153863b69 | 30 | } |
Vdavidovi | 0:13a153863b69 | 31 | |
Vdavidovi | 0:13a153863b69 | 32 | void semafor2() |
Vdavidovi | 0:13a153863b69 | 33 | { |
Vdavidovi | 0:13a153863b69 | 34 | if(t>=0 && t<100) { |
Vdavidovi | 0:13a153863b69 | 35 | vzelena2.light_on(t, 0, 100); |
Vdavidovi | 0:13a153863b69 | 36 | mcrvena2.light_on(t, 0, 100); |
Vdavidovi | 0:13a153863b69 | 37 | vcrvena1.light_on(t, 0, 100); |
Vdavidovi | 0:13a153863b69 | 38 | mzelena1.light_on(t, 0, 100); |
Vdavidovi | 0:13a153863b69 | 39 | } |
Vdavidovi | 0:13a153863b69 | 40 | if(t>=100 && t<200) { |
Vdavidovi | 0:13a153863b69 | 41 | mcrvena2.light_on(t, 100, 200); |
Vdavidovi | 0:13a153863b69 | 42 | vzelena2.light_on(t, 100, 200); |
Vdavidovi | 0:13a153863b69 | 43 | vcrvena1.light_on(t, 100, 200); |
Vdavidovi | 0:13a153863b69 | 44 | mcrvena1.light_on(t, 100, 200); |
Vdavidovi | 0:13a153863b69 | 45 | } |
Vdavidovi | 0:13a153863b69 | 46 | if(t>=200 && t<300) { |
Vdavidovi | 0:13a153863b69 | 47 | vcrvena1.light_on(t, 200,300); |
Vdavidovi | 0:13a153863b69 | 48 | mcrvena1.light_on(t, 200, 300); |
Vdavidovi | 0:13a153863b69 | 49 | vzuta2.light_on(t, 200, 300); |
Vdavidovi | 0:13a153863b69 | 50 | mcrvena2.light_on(t, 200, 300); |
Vdavidovi | 0:13a153863b69 | 51 | } |
Vdavidovi | 0:13a153863b69 | 52 | |
Vdavidovi | 0:13a153863b69 | 53 | |
Vdavidovi | 0:13a153863b69 | 54 | if(t>=300 && t<400) { |
Vdavidovi | 0:13a153863b69 | 55 | vcrvena1.light_on(t, 300,400); |
Vdavidovi | 0:13a153863b69 | 56 | mcrvena1.light_on(t, 300, 400); |
Vdavidovi | 0:13a153863b69 | 57 | vcrvena2.light_on(t, 300, 400); |
Vdavidovi | 0:13a153863b69 | 58 | mcrvena2.light_on(t, 300, 400); |
Vdavidovi | 0:13a153863b69 | 59 | } |
Vdavidovi | 0:13a153863b69 | 60 | if(t>=400 && t<500) { |
Vdavidovi | 0:13a153863b69 | 61 | vzuta1.light_on(t, 400,500); |
Vdavidovi | 0:13a153863b69 | 62 | mcrvena1.light_on(t, 400, 500); |
Vdavidovi | 0:13a153863b69 | 63 | vcrvena2.light_on(t, 400, 500); |
Vdavidovi | 0:13a153863b69 | 64 | mcrvena2.light_on(t, 400, 500); |
Vdavidovi | 0:13a153863b69 | 65 | } |
Vdavidovi | 0:13a153863b69 | 66 | if(t>=500 && t<800) { |
Vdavidovi | 0:13a153863b69 | 67 | vzelena1.light_on(t, 500, 800); |
Vdavidovi | 0:13a153863b69 | 68 | mcrvena1.light_on(t, 500, 800); |
Vdavidovi | 0:13a153863b69 | 69 | vcrvena2.light_on(t, 500, 800); |
Vdavidovi | 0:13a153863b69 | 70 | mzelena2.light_on(t, 500, 800); |
Vdavidovi | 0:13a153863b69 | 71 | } |
Vdavidovi | 0:13a153863b69 | 72 | if(t>=800 && t<900) { |
Vdavidovi | 0:13a153863b69 | 73 | vzelena1.light_on(t, 800,900); |
Vdavidovi | 0:13a153863b69 | 74 | mcrvena1.light_on(t, 800,900); |
Vdavidovi | 0:13a153863b69 | 75 | vcrvena2.light_on(t, 800,900); |
Vdavidovi | 0:13a153863b69 | 76 | mcrvena2.light_on(t, 800,900); |
Vdavidovi | 0:13a153863b69 | 77 | } |
Vdavidovi | 0:13a153863b69 | 78 | if(t>=900 && t<1000) { |
Vdavidovi | 0:13a153863b69 | 79 | vzuta1.light_on(t, 900,1000); |
Vdavidovi | 0:13a153863b69 | 80 | mcrvena1.light_on(t, 900,1000); |
Vdavidovi | 0:13a153863b69 | 81 | vcrvena2.light_on(t, 900,1000); |
Vdavidovi | 0:13a153863b69 | 82 | mcrvena2.light_on(t, 900,1000); |
Vdavidovi | 0:13a153863b69 | 83 | } |
Vdavidovi | 0:13a153863b69 | 84 | if(t>=1000 && t<1100) { |
Vdavidovi | 0:13a153863b69 | 85 | vcrvena1.light_on(t, 1000,1100); |
Vdavidovi | 0:13a153863b69 | 86 | mcrvena1.light_on(t, 1000,1100); |
Vdavidovi | 0:13a153863b69 | 87 | vcrvena2.light_on(t, 1000,1100); |
Vdavidovi | 0:13a153863b69 | 88 | mcrvena2.light_on(t, 1000,1100); |
Vdavidovi | 0:13a153863b69 | 89 | } |
Vdavidovi | 0:13a153863b69 | 90 | if(t>=1100 && t<1200) { |
Vdavidovi | 0:13a153863b69 | 91 | vcrvena1.light_on(t, 1100,1200); |
Vdavidovi | 0:13a153863b69 | 92 | mcrvena1.light_on(t, 1100,1200); |
Vdavidovi | 0:13a153863b69 | 93 | vzuta2.light_on(t, 1100,1200); |
Vdavidovi | 0:13a153863b69 | 94 | mcrvena2.light_on(t, 1100,1200); |
Vdavidovi | 0:13a153863b69 | 95 | } |
Vdavidovi | 0:13a153863b69 | 96 | if(t>=1200 && t<1300) { |
Vdavidovi | 0:13a153863b69 | 97 | vcrvena1.light_on(t, 1200,1300); |
Vdavidovi | 0:13a153863b69 | 98 | mzelena1.light_on(t, 1200,1300); |
Vdavidovi | 0:13a153863b69 | 99 | vzelena2.light_on(t, 1200,1300); |
Vdavidovi | 0:13a153863b69 | 100 | mcrvena2.light_on(t, 1200,1300); |
Vdavidovi | 0:13a153863b69 | 101 | } |
Vdavidovi | 0:13a153863b69 | 102 | } |
Vdavidovi | 0:13a153863b69 | 103 | |
Vdavidovi | 0:13a153863b69 | 104 | |
Vdavidovi | 0:13a153863b69 | 105 | int main() |
Vdavidovi | 0:13a153863b69 | 106 | { |
Vdavidovi | 0:13a153863b69 | 107 | tik1.attach(&tiker1, 0.02); |
Vdavidovi | 0:13a153863b69 | 108 | while(1) { |
Vdavidovi | 0:13a153863b69 | 109 | if(p!=1) |
Vdavidovi | 0:13a153863b69 | 110 | t=0; |
Vdavidovi | 0:13a153863b69 | 111 | vcrvena1.light_on(t, 0, 1); |
Vdavidovi | 0:13a153863b69 | 112 | mzelena1.light_on(t, 0, 1); |
Vdavidovi | 0:13a153863b69 | 113 | vzelena2.light_on(t, 0, 1); |
Vdavidovi | 0:13a153863b69 | 114 | mcrvena2.light_on(t, 0, 1); |
Vdavidovi | 0:13a153863b69 | 115 | tipkalo.fall(&pjesaci); |
Vdavidovi | 0:13a153863b69 | 116 | if(p==1 && t<1200) |
Vdavidovi | 0:13a153863b69 | 117 | semafor2(); |
Vdavidovi | 0:13a153863b69 | 118 | if(p==1 && t>1200) { |
Vdavidovi | 0:13a153863b69 | 119 | t=0; |
Vdavidovi | 0:13a153863b69 | 120 | p=0; |
Vdavidovi | 0:13a153863b69 | 121 | } |
Vdavidovi | 0:13a153863b69 | 122 | } |
Vdavidovi | 0:13a153863b69 | 123 | } |
Vdavidovi | 0:13a153863b69 | 124 | |
Vdavidovi | 0:13a153863b69 | 125 |