tim007 tim007
/
PAI_LV6_Grupa7_Tim007_Zadatak1
Nedim Hozić Emrah Dautbegović
main.cpp@0:5567cb98a73d, 2014-04-24 (annotated)
- Committer:
- tim007
- Date:
- Thu Apr 24 18:17:25 2014 +0000
- Revision:
- 0:5567cb98a73d
LV7_Grupa7_Tim007
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim007 | 0:5567cb98a73d | 1 | #include "mbed.h" |
tim007 | 0:5567cb98a73d | 2 | #include "N5110.h" |
tim007 | 0:5567cb98a73d | 3 | |
tim007 | 0:5567cb98a73d | 4 | //Analogni ulazi sa dzojstika |
tim007 | 0:5567cb98a73d | 5 | AnalogIn VRx(dp11); |
tim007 | 0:5567cb98a73d | 6 | AnalogIn VRy(dp10); |
tim007 | 0:5567cb98a73d | 7 | //Taster sa dzojstika |
tim007 | 0:5567cb98a73d | 8 | DigitalIn SW(dp9); |
tim007 | 0:5567cb98a73d | 9 | //Deklaracija LCD objekta |
tim007 | 0:5567cb98a73d | 10 | N5110 lcd(dp4,dp24,dp23,dp25,dp2,dp6,dp18); |
tim007 | 0:5567cb98a73d | 11 | |
tim007 | 0:5567cb98a73d | 12 | //Digitalni izlaz za deaktivaciju LED buffera |
tim007 | 0:5567cb98a73d | 13 | DigitalOut enable(dp14); |
tim007 | 0:5567cb98a73d | 14 | |
tim007 | 0:5567cb98a73d | 15 | void baklava(int x, int y) |
tim007 | 0:5567cb98a73d | 16 | { |
tim007 | 0:5567cb98a73d | 17 | lcd.clear(); |
tim007 | 0:5567cb98a73d | 18 | lcd.setPixel(x,y); |
tim007 | 0:5567cb98a73d | 19 | lcd.setPixel(x+1, y); |
tim007 | 0:5567cb98a73d | 20 | lcd.setPixel(x+2, y); |
tim007 | 0:5567cb98a73d | 21 | lcd.setPixel(x-1, y); |
tim007 | 0:5567cb98a73d | 22 | lcd.setPixel(x-2, y); |
tim007 | 0:5567cb98a73d | 23 | lcd.setPixel(x, y+1); |
tim007 | 0:5567cb98a73d | 24 | lcd.setPixel(x, y+2); |
tim007 | 0:5567cb98a73d | 25 | lcd.setPixel(x, y-1); |
tim007 | 0:5567cb98a73d | 26 | lcd.setPixel(x,y-2); |
tim007 | 0:5567cb98a73d | 27 | lcd.setPixel(x+1,y+1); |
tim007 | 0:5567cb98a73d | 28 | lcd.setPixel(x-1,y+1); |
tim007 | 0:5567cb98a73d | 29 | lcd.setPixel(x-1,y-1); |
tim007 | 0:5567cb98a73d | 30 | lcd.setPixel(x+1,y-1); |
tim007 | 0:5567cb98a73d | 31 | lcd.refresh(); |
tim007 | 0:5567cb98a73d | 32 | } |
tim007 | 0:5567cb98a73d | 33 | |
tim007 | 0:5567cb98a73d | 34 | void viljuska(int x, int y) |
tim007 | 0:5567cb98a73d | 35 | { |
tim007 | 0:5567cb98a73d | 36 | lcd.setPixel(x+6,y+1); |
tim007 | 0:5567cb98a73d | 37 | lcd.setPixel(x+5,y+2); |
tim007 | 0:5567cb98a73d | 38 | lcd.setPixel(x+4,y+3); |
tim007 | 0:5567cb98a73d | 39 | lcd.setPixel(x+5,y+4); |
tim007 | 0:5567cb98a73d | 40 | lcd.setPixel(x+3,y+3); |
tim007 | 0:5567cb98a73d | 41 | lcd.setPixel(x+2,y+4); |
tim007 | 0:5567cb98a73d | 42 | lcd.setPixel(x+4,y+5); |
tim007 | 0:5567cb98a73d | 43 | lcd.setPixel(x+1,y+5); |
tim007 | 0:5567cb98a73d | 44 | lcd.setPixel(x+3,y+6); |
tim007 | 0:5567cb98a73d | 45 | lcd.refresh(); |
tim007 | 0:5567cb98a73d | 46 | } |
tim007 | 0:5567cb98a73d | 47 | |
tim007 | 0:5567cb98a73d | 48 | int main() |
tim007 | 0:5567cb98a73d | 49 | { |
tim007 | 0:5567cb98a73d | 50 | enable=1; |
tim007 | 0:5567cb98a73d | 51 | |
tim007 | 0:5567cb98a73d | 52 | // inicijalizacija displeja |
tim007 | 0:5567cb98a73d | 53 | lcd.init(); |
tim007 | 0:5567cb98a73d | 54 | lcd.setXYAddress(0,0); |
tim007 | 0:5567cb98a73d | 55 | int x=0, y=0; |
tim007 | 0:5567cb98a73d | 56 | baklava(x,y); |
tim007 | 0:5567cb98a73d | 57 | int i=0; |
tim007 | 0:5567cb98a73d | 58 | bool krecex=false, krecey=false; |
tim007 | 0:5567cb98a73d | 59 | int niz[10] = {4,5,6,7,8,9,10,11,12,13}; |
tim007 | 0:5567cb98a73d | 60 | while(1) |
tim007 | 0:5567cb98a73d | 61 | { |
tim007 | 0:5567cb98a73d | 62 | if (VRx<1.0/3.0) |
tim007 | 0:5567cb98a73d | 63 | { |
tim007 | 0:5567cb98a73d | 64 | if(x>3) |
tim007 | 0:5567cb98a73d | 65 | { |
tim007 | 0:5567cb98a73d | 66 | krecex = true; |
tim007 | 0:5567cb98a73d | 67 | x=x-1; |
tim007 | 0:5567cb98a73d | 68 | } |
tim007 | 0:5567cb98a73d | 69 | baklava(x,y); |
tim007 | 0:5567cb98a73d | 70 | viljuska(x+niz[i], y+niz[i]); |
tim007 | 0:5567cb98a73d | 71 | } |
tim007 | 0:5567cb98a73d | 72 | else if(VRx<2.0/3.0) |
tim007 | 0:5567cb98a73d | 73 | { |
tim007 | 0:5567cb98a73d | 74 | krecex = false; |
tim007 | 0:5567cb98a73d | 75 | baklava(x,y); |
tim007 | 0:5567cb98a73d | 76 | viljuska(x+niz[i], y+niz[i]); |
tim007 | 0:5567cb98a73d | 77 | } |
tim007 | 0:5567cb98a73d | 78 | else |
tim007 | 0:5567cb98a73d | 79 | { |
tim007 | 0:5567cb98a73d | 80 | if(x<80) |
tim007 | 0:5567cb98a73d | 81 | { |
tim007 | 0:5567cb98a73d | 82 | krecex=true; |
tim007 | 0:5567cb98a73d | 83 | x=x+1; |
tim007 | 0:5567cb98a73d | 84 | } |
tim007 | 0:5567cb98a73d | 85 | baklava(x,y); |
tim007 | 0:5567cb98a73d | 86 | viljuska(x+niz[i], y+niz[i]); |
tim007 | 0:5567cb98a73d | 87 | } |
tim007 | 0:5567cb98a73d | 88 | if (VRy<1.0/3.0) |
tim007 | 0:5567cb98a73d | 89 | { |
tim007 | 0:5567cb98a73d | 90 | if(y>3){ |
tim007 | 0:5567cb98a73d | 91 | krecey = true; |
tim007 | 0:5567cb98a73d | 92 | y=y-1; |
tim007 | 0:5567cb98a73d | 93 | } |
tim007 | 0:5567cb98a73d | 94 | baklava(x,y); |
tim007 | 0:5567cb98a73d | 95 | viljuska(x+niz[i], y+niz[i]); |
tim007 | 0:5567cb98a73d | 96 | } |
tim007 | 0:5567cb98a73d | 97 | else if(VRy<2.0/3.0) |
tim007 | 0:5567cb98a73d | 98 | { |
tim007 | 0:5567cb98a73d | 99 | krecey=false; |
tim007 | 0:5567cb98a73d | 100 | baklava(x,y); |
tim007 | 0:5567cb98a73d | 101 | viljuska(x+niz[i], y+niz[i]); |
tim007 | 0:5567cb98a73d | 102 | } |
tim007 | 0:5567cb98a73d | 103 | else |
tim007 | 0:5567cb98a73d | 104 | { |
tim007 | 0:5567cb98a73d | 105 | if(y<45) |
tim007 | 0:5567cb98a73d | 106 | { |
tim007 | 0:5567cb98a73d | 107 | krecey=true; |
tim007 | 0:5567cb98a73d | 108 | y=y+1; |
tim007 | 0:5567cb98a73d | 109 | } |
tim007 | 0:5567cb98a73d | 110 | baklava(x,y); |
tim007 | 0:5567cb98a73d | 111 | viljuska(x+niz[i], y+niz[i]); |
tim007 | 0:5567cb98a73d | 112 | } |
tim007 | 0:5567cb98a73d | 113 | bool krece=krecex||krecey; |
tim007 | 0:5567cb98a73d | 114 | if(krece && i<9) i++; |
tim007 | 0:5567cb98a73d | 115 | else if(krece==false && i>0)i--; |
tim007 | 0:5567cb98a73d | 116 | wait_ms(100); |
tim007 | 0:5567cb98a73d | 117 | } |
tim007 | 0:5567cb98a73d | 118 | } |
tim007 | 0:5567cb98a73d | 119 |