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