tim008 tim008
/
Tim008_EditorBitmape
Haris Šemić, Emina Šarić
main.cpp@3:27c6c5d1fe5f, 2014-06-12 (annotated)
- Committer:
- tim008
- Date:
- Thu Jun 12 13:57:57 2014 +0000
- Revision:
- 3:27c6c5d1fe5f
- Parent:
- 2:f923d0ef12ec
Haris ?emi?, Emina ?ari?
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim008 | 0:24887104b8f0 | 1 | #include "mbed.h" |
tim008 | 0:24887104b8f0 | 2 | #include "Serial.h" |
tim008 | 0:24887104b8f0 | 3 | #include "N5110.h" |
tim008 | 0:24887104b8f0 | 4 | |
tim008 | 0:24887104b8f0 | 5 | Serial pc(USBTX, USBRX); |
tim008 | 0:24887104b8f0 | 6 | N5110 displej(dp4,dp24,dp23,dp25,dp2,dp6,dp18); |
tim008 | 0:24887104b8f0 | 7 | |
tim008 | 1:441a9c43ffda | 8 | AnalogIn VRx(dp11); |
tim008 | 1:441a9c43ffda | 9 | AnalogIn VRy(dp10); |
tim008 | 1:441a9c43ffda | 10 | |
tim008 | 1:441a9c43ffda | 11 | DigitalIn taster1(dp1); |
tim008 | 2:f923d0ef12ec | 12 | //DigitalIn taster2(dp2); |
tim008 | 1:441a9c43ffda | 13 | |
tim008 | 1:441a9c43ffda | 14 | DigitalIn SW(dp9); |
tim008 | 1:441a9c43ffda | 15 | |
tim008 | 3:27c6c5d1fe5f | 16 | int detektirajPozadinu(int x, int y) |
tim008 | 3:27c6c5d1fe5f | 17 | {/* |
tim008 | 1:441a9c43ffda | 18 | if(x>83 || x<0 || y>47 || y<0) return 'x'; |
tim008 | 1:441a9c43ffda | 19 | int brRubnih(0), brCrnih(0); |
tim008 | 1:441a9c43ffda | 20 | unsigned char gore,dole,lijevo,desno; |
tim008 | 2:f923d0ef12ec | 21 | if(x == 0) lijevo = 'x'; |
tim008 | 2:f923d0ef12ec | 22 | else lijevo = displej.getPixel(x-1,y); |
tim008 | 2:f923d0ef12ec | 23 | if(x == 83) desno = 'x'; |
tim008 | 2:f923d0ef12ec | 24 | else desno = displej.getPixel(x+1,y); |
tim008 | 2:f923d0ef12ec | 25 | if(y == 0) dole = 'x'; |
tim008 | 2:f923d0ef12ec | 26 | else dole = displej.getPixel(x,y-1); |
tim008 | 2:f923d0ef12ec | 27 | if(y == 47) gore = 'x'; |
tim008 | 2:f923d0ef12ec | 28 | else gore = displej.getPixel(x,y+1); |
tim008 | 2:f923d0ef12ec | 29 | if(lijevo == '0') brCrnih++; |
tim008 | 2:f923d0ef12ec | 30 | else if(lijevo == 'x') brRubnih++; |
tim008 | 2:f923d0ef12ec | 31 | if(desno == '0') brCrnih++; |
tim008 | 2:f923d0ef12ec | 32 | else if(desno == 'x') brRubnih++; |
tim008 | 2:f923d0ef12ec | 33 | if(gore == '0') brCrnih++; |
tim008 | 2:f923d0ef12ec | 34 | else if(gore == 'x') brRubnih++; |
tim008 | 2:f923d0ef12ec | 35 | if(dole == '0') brCrnih++; |
tim008 | 2:f923d0ef12ec | 36 | else if(dole == 'x') brRubnih++; |
tim008 | 1:441a9c43ffda | 37 | int brBijelih(4-brCrnih-brRubnih); |
tim008 | 1:441a9c43ffda | 38 | if(brBijelih < brCrnih) return 'c'; |
tim008 | 3:27c6c5d1fe5f | 39 | return 'b';*/ |
tim008 | 3:27c6c5d1fe5f | 40 | |
tim008 | 3:27c6c5d1fe5f | 41 | if(x>83 || x<0 || y<0 || y>47) return -1; |
tim008 | 3:27c6c5d1fe5f | 42 | int gore,dole,desno,lijevo; |
tim008 | 3:27c6c5d1fe5f | 43 | |
tim008 | 3:27c6c5d1fe5f | 44 | if(x == 0) lijevo = -1; |
tim008 | 3:27c6c5d1fe5f | 45 | else { |
tim008 | 3:27c6c5d1fe5f | 46 | lijevo = displej.getPixel(x-1,y); |
tim008 | 3:27c6c5d1fe5f | 47 | if(lijevo != 0) lijevo=1; |
tim008 | 3:27c6c5d1fe5f | 48 | } |
tim008 | 3:27c6c5d1fe5f | 49 | if(x == 83) desno = -1; |
tim008 | 3:27c6c5d1fe5f | 50 | else { |
tim008 | 3:27c6c5d1fe5f | 51 | desno = displej.getPixel(x+1,y); |
tim008 | 3:27c6c5d1fe5f | 52 | if(desno !=0) desno=1; |
tim008 | 3:27c6c5d1fe5f | 53 | } |
tim008 | 3:27c6c5d1fe5f | 54 | if(y == 0) dole = -1; |
tim008 | 3:27c6c5d1fe5f | 55 | else { |
tim008 | 3:27c6c5d1fe5f | 56 | dole = displej.getPixel(x,y-1); |
tim008 | 3:27c6c5d1fe5f | 57 | if(dole!=0) dole=1; |
tim008 | 3:27c6c5d1fe5f | 58 | } |
tim008 | 3:27c6c5d1fe5f | 59 | if(y == 47) gore = -1; |
tim008 | 3:27c6c5d1fe5f | 60 | else { |
tim008 | 3:27c6c5d1fe5f | 61 | gore = displej.getPixel(x,y+1); |
tim008 | 3:27c6c5d1fe5f | 62 | if(gore!=0) gore=1; |
tim008 | 3:27c6c5d1fe5f | 63 | } |
tim008 | 3:27c6c5d1fe5f | 64 | int okolo[4]={gore,dole,lijevo,desno}; |
tim008 | 3:27c6c5d1fe5f | 65 | int clear(0),set(0),rub(0); |
tim008 | 3:27c6c5d1fe5f | 66 | for(int i=0;i<4;i++) { |
tim008 | 3:27c6c5d1fe5f | 67 | if(okolo[i]==1) set++; |
tim008 | 3:27c6c5d1fe5f | 68 | if(okolo[i]==0) clear++; |
tim008 | 3:27c6c5d1fe5f | 69 | if(okolo[i]==-1) rub++; |
tim008 | 3:27c6c5d1fe5f | 70 | } |
tim008 | 3:27c6c5d1fe5f | 71 | if(set>clear) return 1; |
tim008 | 3:27c6c5d1fe5f | 72 | if(clear>set) return 0; |
tim008 | 3:27c6c5d1fe5f | 73 | return -1; |
tim008 | 1:441a9c43ffda | 74 | } |
tim008 | 1:441a9c43ffda | 75 | |
tim008 | 2:f923d0ef12ec | 76 | void postaviKursor(int x, int y) |
tim008 | 2:f923d0ef12ec | 77 | { |
tim008 | 2:f923d0ef12ec | 78 | /*for(int i(1); i<5; i++) { |
tim008 | 1:441a9c43ffda | 79 | char pozadina(detektirajPozadinu(x+i, y)); |
tim008 | 1:441a9c43ffda | 80 | if(pozadina == 'b') |
tim008 | 1:441a9c43ffda | 81 | displej.setPixel(x+i,y); |
tim008 | 1:441a9c43ffda | 82 | else if(pozadina == 'c') displej.clearPixel(x+i,y); |
tim008 | 1:441a9c43ffda | 83 | pozadina=detektirajPozadinu(x, y+i); |
tim008 | 1:441a9c43ffda | 84 | if(pozadina == 'b') |
tim008 | 1:441a9c43ffda | 85 | displej.setPixel(x,y+i); |
tim008 | 1:441a9c43ffda | 86 | else if(pozadina == 'c') displej.clearPixel(x,y+i); |
tim008 | 1:441a9c43ffda | 87 | pozadina=detektirajPozadinu(x-i, y); |
tim008 | 1:441a9c43ffda | 88 | if(pozadina == 'b') |
tim008 | 1:441a9c43ffda | 89 | displej.setPixel(x-i,y); |
tim008 | 1:441a9c43ffda | 90 | else if(pozadina == 'c') displej.clearPixel(x-i,y); |
tim008 | 1:441a9c43ffda | 91 | pozadina=detektirajPozadinu(x, y-i); |
tim008 | 1:441a9c43ffda | 92 | if(pozadina == 'b') |
tim008 | 1:441a9c43ffda | 93 | displej.setPixel(x,y-i); |
tim008 | 1:441a9c43ffda | 94 | else if(pozadina == 'c') displej.clearPixel(x,y-i); |
tim008 | 2:f923d0ef12ec | 95 | }*/ |
tim008 | 2:f923d0ef12ec | 96 | displej.setPixel(x,y); |
tim008 | 2:f923d0ef12ec | 97 | wait(0.01); |
tim008 | 1:441a9c43ffda | 98 | } |
tim008 | 1:441a9c43ffda | 99 | |
tim008 | 2:f923d0ef12ec | 100 | int main() |
tim008 | 2:f923d0ef12ec | 101 | { |
tim008 | 1:441a9c43ffda | 102 | SW.mode(PullUp); |
tim008 | 1:441a9c43ffda | 103 | displej.init(); |
tim008 | 1:441a9c43ffda | 104 | displej.setXYAddress(0,0); |
tim008 | 2:f923d0ef12ec | 105 | int x(0),y(0); |
tim008 | 0:24887104b8f0 | 106 | pc.baud(115200); |
tim008 | 2:f923d0ef12ec | 107 | for(int i=0; i<84; i++) { |
tim008 | 2:f923d0ef12ec | 108 | for(int j=0; j<48; j++) { |
tim008 | 1:441a9c43ffda | 109 | if(pc.getc()=='1') { |
tim008 | 1:441a9c43ffda | 110 | displej.setXYAddress(0,0); |
tim008 | 2:f923d0ef12ec | 111 | displej.setPixel(i,j); |
tim008 | 0:24887104b8f0 | 112 | } |
tim008 | 0:24887104b8f0 | 113 | } |
tim008 | 2:f923d0ef12ec | 114 | } |
tim008 | 2:f923d0ef12ec | 115 | while(1) { |
tim008 | 2:f923d0ef12ec | 116 | if(VRx<1.0/3.0) { |
tim008 | 1:441a9c43ffda | 117 | if (x>0) { |
tim008 | 1:441a9c43ffda | 118 | x--; |
tim008 | 1:441a9c43ffda | 119 | } |
tim008 | 2:f923d0ef12ec | 120 | } |
tim008 | 2:f923d0ef12ec | 121 | |
tim008 | 1:441a9c43ffda | 122 | else if (VRx>2.0/3.0) { |
tim008 | 1:441a9c43ffda | 123 | if(x<83) { |
tim008 | 2:f923d0ef12ec | 124 | x++; |
tim008 | 1:441a9c43ffda | 125 | } |
tim008 | 2:f923d0ef12ec | 126 | } |
tim008 | 2:f923d0ef12ec | 127 | |
tim008 | 1:441a9c43ffda | 128 | if (VRy<1.0/3.0) { |
tim008 | 1:441a9c43ffda | 129 | if(y>0) { |
tim008 | 1:441a9c43ffda | 130 | y--; |
tim008 | 1:441a9c43ffda | 131 | } |
tim008 | 1:441a9c43ffda | 132 | } |
tim008 | 2:f923d0ef12ec | 133 | |
tim008 | 1:441a9c43ffda | 134 | else if (VRy>2.0/3.0) { |
tim008 | 1:441a9c43ffda | 135 | if(y<47) { |
tim008 | 1:441a9c43ffda | 136 | y++; |
tim008 | 1:441a9c43ffda | 137 | } |
tim008 | 1:441a9c43ffda | 138 | } |
tim008 | 2:f923d0ef12ec | 139 | |
tim008 | 1:441a9c43ffda | 140 | //saranje |
tim008 | 1:441a9c43ffda | 141 | postaviKursor(x,y); |
tim008 | 1:441a9c43ffda | 142 | if(taster1==1) { |
tim008 | 1:441a9c43ffda | 143 | if(displej.getPixel(x,y) == '0') |
tim008 | 1:441a9c43ffda | 144 | displej.setPixel(x,y); |
tim008 | 1:441a9c43ffda | 145 | else displej.clearPixel(x,y); |
tim008 | 1:441a9c43ffda | 146 | } |
tim008 | 2:f923d0ef12ec | 147 | |
tim008 | 1:441a9c43ffda | 148 | //prenos na racunar |
tim008 | 2:f923d0ef12ec | 149 | if(pc.readable() == 1) { |
tim008 | 2:f923d0ef12ec | 150 | if(pc.getc() == 'x') { |
tim008 | 2:f923d0ef12ec | 151 | for(int i=0; i<84; i++) { |
tim008 | 2:f923d0ef12ec | 152 | for(int j=0; j<48; j++) { |
tim008 | 2:f923d0ef12ec | 153 | displej.setXYAddress(0,0); |
tim008 | 2:f923d0ef12ec | 154 | if(displej.getPixel(i, j) == 0) |
tim008 | 2:f923d0ef12ec | 155 | pc.putc('0'); |
tim008 | 2:f923d0ef12ec | 156 | else if (displej.getPixel(i, j)==1) pc.putc('1'); |
tim008 | 2:f923d0ef12ec | 157 | else pc.putc('1'); |
tim008 | 2:f923d0ef12ec | 158 | } |
tim008 | 1:441a9c43ffda | 159 | } |
tim008 | 2:f923d0ef12ec | 160 | pc.putc('\n'); |
tim008 | 1:441a9c43ffda | 161 | } |
tim008 | 2:f923d0ef12ec | 162 | } |
tim008 | 0:24887104b8f0 | 163 | displej.refresh(); |
tim008 | 0:24887104b8f0 | 164 | } |
tim008 | 2:f923d0ef12ec | 165 | |
tim008 | 1:441a9c43ffda | 166 | } |