tim007 tim007
/
Projekat_Tim007_Grupa3_2cas
Goro Faruk Predrag Simanić
main.cpp@0:4a555e5d13e6, 2014-05-26 (annotated)
- Committer:
- tim007
- Date:
- Mon May 26 16:01:11 2014 +0000
- Revision:
- 0:4a555e5d13e6
Projekat_Goro_Simanic
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim007 | 0:4a555e5d13e6 | 1 | #include "mbed.h" |
tim007 | 0:4a555e5d13e6 | 2 | #include "N5110.h" |
tim007 | 0:4a555e5d13e6 | 3 | |
tim007 | 0:4a555e5d13e6 | 4 | #define MAXWIDTH 84 |
tim007 | 0:4a555e5d13e6 | 5 | #define MAXHEIGHT 48 |
tim007 | 0:4a555e5d13e6 | 6 | |
tim007 | 0:4a555e5d13e6 | 7 | Timer t; |
tim007 | 0:4a555e5d13e6 | 8 | DigitalOut enable(dp14); |
tim007 | 0:4a555e5d13e6 | 9 | int X1=7,X2=73;int Y=20; |
tim007 | 0:4a555e5d13e6 | 10 | int x1=90,y1=90,x2,y2; |
tim007 | 0:4a555e5d13e6 | 11 | |
tim007 | 0:4a555e5d13e6 | 12 | int x=30,y=30; |
tim007 | 0:4a555e5d13e6 | 13 | AnalogIn VRy2(dp11); |
tim007 | 0:4a555e5d13e6 | 14 | AnalogIn VRy1(dp10); |
tim007 | 0:4a555e5d13e6 | 15 | DigitalIn SW1(dp9), SW2(dp13); |
tim007 | 0:4a555e5d13e6 | 16 | |
tim007 | 0:4a555e5d13e6 | 17 | N5110 lcd (dp4, dp24, dp23, dp25, dp2, dp6, dp18); |
tim007 | 0:4a555e5d13e6 | 18 | |
tim007 | 0:4a555e5d13e6 | 19 | int l=1; |
tim007 | 0:4a555e5d13e6 | 20 | void palija1(int x, int y) |
tim007 | 0:4a555e5d13e6 | 21 | { |
tim007 | 0:4a555e5d13e6 | 22 | int i=7; |
tim007 | 0:4a555e5d13e6 | 23 | if(y>6 && y<33) |
tim007 | 0:4a555e5d13e6 | 24 | for(int j=y; j<=y+2; j++) |
tim007 | 0:4a555e5d13e6 | 25 | { |
tim007 | 0:4a555e5d13e6 | 26 | lcd.clearPixel(i,j-1); |
tim007 | 0:4a555e5d13e6 | 27 | lcd.setPixel(i,j); |
tim007 | 0:4a555e5d13e6 | 28 | lcd.setPixel(i,j+1); |
tim007 | 0:4a555e5d13e6 | 29 | lcd.setPixel(i,j+2); |
tim007 | 0:4a555e5d13e6 | 30 | lcd.setPixel(i,j+3); |
tim007 | 0:4a555e5d13e6 | 31 | lcd.clearPixel(i,j+4); |
tim007 | 0:4a555e5d13e6 | 32 | lcd.refresh(); |
tim007 | 0:4a555e5d13e6 | 33 | } |
tim007 | 0:4a555e5d13e6 | 34 | } |
tim007 | 0:4a555e5d13e6 | 35 | |
tim007 | 0:4a555e5d13e6 | 36 | void palija2(int x, int y) |
tim007 | 0:4a555e5d13e6 | 37 | { |
tim007 | 0:4a555e5d13e6 | 38 | int i=73; |
tim007 | 0:4a555e5d13e6 | 39 | if(y>6 && y<33) |
tim007 | 0:4a555e5d13e6 | 40 | for(int j=y; j<=y+2; j++) |
tim007 | 0:4a555e5d13e6 | 41 | { |
tim007 | 0:4a555e5d13e6 | 42 | lcd.clearPixel(i,j-1); |
tim007 | 0:4a555e5d13e6 | 43 | lcd.setPixel(i,j); |
tim007 | 0:4a555e5d13e6 | 44 | lcd.setPixel(i,j+1); |
tim007 | 0:4a555e5d13e6 | 45 | lcd.setPixel(i,j+2); |
tim007 | 0:4a555e5d13e6 | 46 | lcd.setPixel(i,j+3); |
tim007 | 0:4a555e5d13e6 | 47 | lcd.clearPixel(i,j+4); |
tim007 | 0:4a555e5d13e6 | 48 | lcd.refresh(); |
tim007 | 0:4a555e5d13e6 | 49 | } |
tim007 | 0:4a555e5d13e6 | 50 | } |
tim007 | 0:4a555e5d13e6 | 51 | |
tim007 | 0:4a555e5d13e6 | 52 | void Teren() |
tim007 | 0:4a555e5d13e6 | 53 | { |
tim007 | 0:4a555e5d13e6 | 54 | lcd.setXYAddress(0,0); |
tim007 | 0:4a555e5d13e6 | 55 | int j =5; |
tim007 | 0:4a555e5d13e6 | 56 | for(int i =5;i<= 75;i++) |
tim007 | 0:4a555e5d13e6 | 57 | { |
tim007 | 0:4a555e5d13e6 | 58 | lcd.setPixel(i,j); |
tim007 | 0:4a555e5d13e6 | 59 | lcd.refresh(); |
tim007 | 0:4a555e5d13e6 | 60 | } |
tim007 | 0:4a555e5d13e6 | 61 | int k=75; |
tim007 | 0:4a555e5d13e6 | 62 | for(int i=5;i<=40;i++) |
tim007 | 0:4a555e5d13e6 | 63 | { |
tim007 | 0:4a555e5d13e6 | 64 | lcd.setPixel(k,i); |
tim007 | 0:4a555e5d13e6 | 65 | lcd.refresh(); |
tim007 | 0:4a555e5d13e6 | 66 | } |
tim007 | 0:4a555e5d13e6 | 67 | j=40; |
tim007 | 0:4a555e5d13e6 | 68 | for(int i =75;i>=5;i--) |
tim007 | 0:4a555e5d13e6 | 69 | { |
tim007 | 0:4a555e5d13e6 | 70 | lcd.setPixel (i,j); |
tim007 | 0:4a555e5d13e6 | 71 | lcd.refresh(); |
tim007 | 0:4a555e5d13e6 | 72 | |
tim007 | 0:4a555e5d13e6 | 73 | } |
tim007 | 0:4a555e5d13e6 | 74 | |
tim007 | 0:4a555e5d13e6 | 75 | k=5; |
tim007 | 0:4a555e5d13e6 | 76 | for(int i = 40; i>= 5;i--) |
tim007 | 0:4a555e5d13e6 | 77 | { |
tim007 | 0:4a555e5d13e6 | 78 | lcd.setPixel(k,i); |
tim007 | 0:4a555e5d13e6 | 79 | lcd.refresh(); |
tim007 | 0:4a555e5d13e6 | 80 | |
tim007 | 0:4a555e5d13e6 | 81 | } |
tim007 | 0:4a555e5d13e6 | 82 | |
tim007 | 0:4a555e5d13e6 | 83 | j=40; |
tim007 | 0:4a555e5d13e6 | 84 | for(int i=5;i<=40;i++) |
tim007 | 0:4a555e5d13e6 | 85 | { |
tim007 | 0:4a555e5d13e6 | 86 | lcd.setPixel(j,i); |
tim007 | 0:4a555e5d13e6 | 87 | lcd.refresh(); |
tim007 | 0:4a555e5d13e6 | 88 | |
tim007 | 0:4a555e5d13e6 | 89 | } |
tim007 | 0:4a555e5d13e6 | 90 | |
tim007 | 0:4a555e5d13e6 | 91 | } |
tim007 | 0:4a555e5d13e6 | 92 | |
tim007 | 0:4a555e5d13e6 | 93 | void Gore(int &x, int &y) |
tim007 | 0:4a555e5d13e6 | 94 | { |
tim007 | 0:4a555e5d13e6 | 95 | if(y>0) |
tim007 | 0:4a555e5d13e6 | 96 | { |
tim007 | 0:4a555e5d13e6 | 97 | lcd.clearPixel(x,y+1); |
tim007 | 0:4a555e5d13e6 | 98 | y=y-1; |
tim007 | 0:4a555e5d13e6 | 99 | |
tim007 | 0:4a555e5d13e6 | 100 | |
tim007 | 0:4a555e5d13e6 | 101 | } |
tim007 | 0:4a555e5d13e6 | 102 | } |
tim007 | 0:4a555e5d13e6 | 103 | |
tim007 | 0:4a555e5d13e6 | 104 | void Dole(int &x, int &y) |
tim007 | 0:4a555e5d13e6 | 105 | { |
tim007 | 0:4a555e5d13e6 | 106 | if(y<33) |
tim007 | 0:4a555e5d13e6 | 107 | { |
tim007 | 0:4a555e5d13e6 | 108 | lcd.clearPixel(x,y-1); |
tim007 | 0:4a555e5d13e6 | 109 | y=y+1; |
tim007 | 0:4a555e5d13e6 | 110 | |
tim007 | 0:4a555e5d13e6 | 111 | } |
tim007 | 0:4a555e5d13e6 | 112 | } |
tim007 | 0:4a555e5d13e6 | 113 | |
tim007 | 0:4a555e5d13e6 | 114 | void kretanjeLoptice() |
tim007 | 0:4a555e5d13e6 | 115 | { |
tim007 | 0:4a555e5d13e6 | 116 | if (l==1) |
tim007 | 0:4a555e5d13e6 | 117 | { |
tim007 | 0:4a555e5d13e6 | 118 | while (x!=8) |
tim007 | 0:4a555e5d13e6 | 119 | { |
tim007 | 0:4a555e5d13e6 | 120 | x--; |
tim007 | 0:4a555e5d13e6 | 121 | lcd.setPixel(x,y); |
tim007 | 0:4a555e5d13e6 | 122 | lcd.setPixel(x,y+1); |
tim007 | 0:4a555e5d13e6 | 123 | lcd.setPixel(x+1,y); |
tim007 | 0:4a555e5d13e6 | 124 | lcd.setPixel(x+1,y+1); |
tim007 | 0:4a555e5d13e6 | 125 | lcd.clearPixel(x+2,y); |
tim007 | 0:4a555e5d13e6 | 126 | lcd.clearPixel(x+2,y+1); |
tim007 | 0:4a555e5d13e6 | 127 | lcd.refresh(); |
tim007 | 0:4a555e5d13e6 | 128 | wait(0.05); |
tim007 | 0:4a555e5d13e6 | 129 | } |
tim007 | 0:4a555e5d13e6 | 130 | l=0; |
tim007 | 0:4a555e5d13e6 | 131 | } |
tim007 | 0:4a555e5d13e6 | 132 | if (l==0) |
tim007 | 0:4a555e5d13e6 | 133 | { |
tim007 | 0:4a555e5d13e6 | 134 | while (x!=72) |
tim007 | 0:4a555e5d13e6 | 135 | { |
tim007 | 0:4a555e5d13e6 | 136 | x++; |
tim007 | 0:4a555e5d13e6 | 137 | lcd.setPixel(x,y); |
tim007 | 0:4a555e5d13e6 | 138 | lcd.setPixel(x,y+1); |
tim007 | 0:4a555e5d13e6 | 139 | lcd.setPixel(x+1,y); |
tim007 | 0:4a555e5d13e6 | 140 | lcd.setPixel(x+1,y+1); |
tim007 | 0:4a555e5d13e6 | 141 | lcd.clearPixel(x-2,y); |
tim007 | 0:4a555e5d13e6 | 142 | lcd.clearPixel(x-2,y+1); |
tim007 | 0:4a555e5d13e6 | 143 | lcd.refresh(); |
tim007 | 0:4a555e5d13e6 | 144 | wait(0.05); |
tim007 | 0:4a555e5d13e6 | 145 | } |
tim007 | 0:4a555e5d13e6 | 146 | l=1; |
tim007 | 0:4a555e5d13e6 | 147 | x=72; |
tim007 | 0:4a555e5d13e6 | 148 | } |
tim007 | 0:4a555e5d13e6 | 149 | |
tim007 | 0:4a555e5d13e6 | 150 | |
tim007 | 0:4a555e5d13e6 | 151 | |
tim007 | 0:4a555e5d13e6 | 152 | } |
tim007 | 0:4a555e5d13e6 | 153 | |
tim007 | 0:4a555e5d13e6 | 154 | void loptica() |
tim007 | 0:4a555e5d13e6 | 155 | { |
tim007 | 0:4a555e5d13e6 | 156 | lcd.setPixel(30,30); |
tim007 | 0:4a555e5d13e6 | 157 | lcd.setPixel(31,31); |
tim007 | 0:4a555e5d13e6 | 158 | lcd.setPixel(30,31); |
tim007 | 0:4a555e5d13e6 | 159 | lcd.setPixel(31,30); |
tim007 | 0:4a555e5d13e6 | 160 | lcd.refresh(); |
tim007 | 0:4a555e5d13e6 | 161 | } |
tim007 | 0:4a555e5d13e6 | 162 | |
tim007 | 0:4a555e5d13e6 | 163 | int main() |
tim007 | 0:4a555e5d13e6 | 164 | { |
tim007 | 0:4a555e5d13e6 | 165 | lcd.setXYAddress(0,0); |
tim007 | 0:4a555e5d13e6 | 166 | enable = 1; |
tim007 | 0:4a555e5d13e6 | 167 | SW1.mode(PullUp); |
tim007 | 0:4a555e5d13e6 | 168 | SW2.mode(PullUp); |
tim007 | 0:4a555e5d13e6 | 169 | t.start(); |
tim007 | 0:4a555e5d13e6 | 170 | lcd.init(); |
tim007 | 0:4a555e5d13e6 | 171 | Teren(); |
tim007 | 0:4a555e5d13e6 | 172 | palija1(X1,Y); |
tim007 | 0:4a555e5d13e6 | 173 | loptica(); |
tim007 | 0:4a555e5d13e6 | 174 | palija2(X2,Y); |
tim007 | 0:4a555e5d13e6 | 175 | while(1){ |
tim007 | 0:4a555e5d13e6 | 176 | kretanjeLoptice(); |
tim007 | 0:4a555e5d13e6 | 177 | if(VRy1 < 1.0/3.0) |
tim007 | 0:4a555e5d13e6 | 178 | { |
tim007 | 0:4a555e5d13e6 | 179 | lcd.refresh(); |
tim007 | 0:4a555e5d13e6 | 180 | Gore(X1,Y); |
tim007 | 0:4a555e5d13e6 | 181 | palija1(X1,Y); |
tim007 | 0:4a555e5d13e6 | 182 | } |
tim007 | 0:4a555e5d13e6 | 183 | else if(VRy1 > 2.0/3.0) |
tim007 | 0:4a555e5d13e6 | 184 | { |
tim007 | 0:4a555e5d13e6 | 185 | lcd.refresh(); |
tim007 | 0:4a555e5d13e6 | 186 | Dole(X1,Y); |
tim007 | 0:4a555e5d13e6 | 187 | palija1(X1,Y); |
tim007 | 0:4a555e5d13e6 | 188 | } |
tim007 | 0:4a555e5d13e6 | 189 | |
tim007 | 0:4a555e5d13e6 | 190 | if(VRy2 < 1.0/3.0) |
tim007 | 0:4a555e5d13e6 | 191 | { |
tim007 | 0:4a555e5d13e6 | 192 | lcd.refresh(); |
tim007 | 0:4a555e5d13e6 | 193 | Gore(X2,Y); |
tim007 | 0:4a555e5d13e6 | 194 | palija2(X2,Y); |
tim007 | 0:4a555e5d13e6 | 195 | } |
tim007 | 0:4a555e5d13e6 | 196 | else if(VRy2 > 2.0/3.0) |
tim007 | 0:4a555e5d13e6 | 197 | { |
tim007 | 0:4a555e5d13e6 | 198 | lcd.refresh(); |
tim007 | 0:4a555e5d13e6 | 199 | Dole(X2,Y); |
tim007 | 0:4a555e5d13e6 | 200 | palija2(X2,Y); |
tim007 | 0:4a555e5d13e6 | 201 | } |
tim007 | 0:4a555e5d13e6 | 202 | } |
tim007 | 0:4a555e5d13e6 | 203 | } |
tim007 | 0:4a555e5d13e6 | 204 |