tim008 tim008
/
Tim008_EditorBitmape
Haris Šemić, Emina Šarić
main.cpp@2:f923d0ef12ec, 2014-06-12 (annotated)
- Committer:
- tim008
- Date:
- Thu Jun 12 13:09:51 2014 +0000
- Revision:
- 2:f923d0ef12ec
- Parent:
- 1:441a9c43ffda
- Child:
- 3:27c6c5d1fe5f
Emina ?ari?, Haris ?emi?
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 | 2:f923d0ef12ec | 16 | char detektirajPozadinu(int x, int y) |
tim008 | 2:f923d0ef12ec | 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 | 1:441a9c43ffda | 39 | return 'b'; |
tim008 | 1:441a9c43ffda | 40 | } |
tim008 | 1:441a9c43ffda | 41 | |
tim008 | 2:f923d0ef12ec | 42 | void postaviKursor(int x, int y) |
tim008 | 2:f923d0ef12ec | 43 | { |
tim008 | 2:f923d0ef12ec | 44 | /*for(int i(1); i<5; i++) { |
tim008 | 1:441a9c43ffda | 45 | char pozadina(detektirajPozadinu(x+i, y)); |
tim008 | 1:441a9c43ffda | 46 | if(pozadina == 'b') |
tim008 | 1:441a9c43ffda | 47 | displej.setPixel(x+i,y); |
tim008 | 1:441a9c43ffda | 48 | else if(pozadina == 'c') displej.clearPixel(x+i,y); |
tim008 | 1:441a9c43ffda | 49 | pozadina=detektirajPozadinu(x, y+i); |
tim008 | 1:441a9c43ffda | 50 | if(pozadina == 'b') |
tim008 | 1:441a9c43ffda | 51 | displej.setPixel(x,y+i); |
tim008 | 1:441a9c43ffda | 52 | else if(pozadina == 'c') displej.clearPixel(x,y+i); |
tim008 | 1:441a9c43ffda | 53 | pozadina=detektirajPozadinu(x-i, y); |
tim008 | 1:441a9c43ffda | 54 | if(pozadina == 'b') |
tim008 | 1:441a9c43ffda | 55 | displej.setPixel(x-i,y); |
tim008 | 1:441a9c43ffda | 56 | else if(pozadina == 'c') displej.clearPixel(x-i,y); |
tim008 | 1:441a9c43ffda | 57 | pozadina=detektirajPozadinu(x, y-i); |
tim008 | 1:441a9c43ffda | 58 | if(pozadina == 'b') |
tim008 | 1:441a9c43ffda | 59 | displej.setPixel(x,y-i); |
tim008 | 1:441a9c43ffda | 60 | else if(pozadina == 'c') displej.clearPixel(x,y-i); |
tim008 | 2:f923d0ef12ec | 61 | }*/ |
tim008 | 2:f923d0ef12ec | 62 | displej.setPixel(x,y); |
tim008 | 2:f923d0ef12ec | 63 | wait(0.01); |
tim008 | 1:441a9c43ffda | 64 | } |
tim008 | 1:441a9c43ffda | 65 | |
tim008 | 2:f923d0ef12ec | 66 | int main() |
tim008 | 2:f923d0ef12ec | 67 | { |
tim008 | 1:441a9c43ffda | 68 | SW.mode(PullUp); |
tim008 | 1:441a9c43ffda | 69 | displej.init(); |
tim008 | 1:441a9c43ffda | 70 | displej.setXYAddress(0,0); |
tim008 | 2:f923d0ef12ec | 71 | int x(0),y(0); |
tim008 | 0:24887104b8f0 | 72 | pc.baud(115200); |
tim008 | 2:f923d0ef12ec | 73 | for(int i=0; i<84; i++) { |
tim008 | 2:f923d0ef12ec | 74 | for(int j=0; j<48; j++) { |
tim008 | 1:441a9c43ffda | 75 | if(pc.getc()=='1') { |
tim008 | 1:441a9c43ffda | 76 | displej.setXYAddress(0,0); |
tim008 | 2:f923d0ef12ec | 77 | displej.setPixel(i,j); |
tim008 | 0:24887104b8f0 | 78 | } |
tim008 | 0:24887104b8f0 | 79 | } |
tim008 | 2:f923d0ef12ec | 80 | } |
tim008 | 2:f923d0ef12ec | 81 | while(1) { |
tim008 | 2:f923d0ef12ec | 82 | /* if(pc.readable() == 1) { |
tim008 | 2:f923d0ef12ec | 83 | if(pc.getc() != 'x') { |
tim008 | 2:f923d0ef12ec | 84 | |
tim008 | 2:f923d0ef12ec | 85 | } |
tim008 | 2:f923d0ef12ec | 86 | } */ |
tim008 | 2:f923d0ef12ec | 87 | if(VRx<1.0/3.0) { |
tim008 | 1:441a9c43ffda | 88 | if (x>0) { |
tim008 | 1:441a9c43ffda | 89 | x--; |
tim008 | 1:441a9c43ffda | 90 | } |
tim008 | 2:f923d0ef12ec | 91 | } |
tim008 | 2:f923d0ef12ec | 92 | |
tim008 | 1:441a9c43ffda | 93 | else if (VRx>2.0/3.0) { |
tim008 | 1:441a9c43ffda | 94 | if(x<83) { |
tim008 | 2:f923d0ef12ec | 95 | x++; |
tim008 | 1:441a9c43ffda | 96 | } |
tim008 | 2:f923d0ef12ec | 97 | } |
tim008 | 2:f923d0ef12ec | 98 | |
tim008 | 1:441a9c43ffda | 99 | if (VRy<1.0/3.0) { |
tim008 | 1:441a9c43ffda | 100 | if(y>0) { |
tim008 | 1:441a9c43ffda | 101 | y--; |
tim008 | 1:441a9c43ffda | 102 | } |
tim008 | 1:441a9c43ffda | 103 | } |
tim008 | 2:f923d0ef12ec | 104 | |
tim008 | 1:441a9c43ffda | 105 | else if (VRy>2.0/3.0) { |
tim008 | 1:441a9c43ffda | 106 | if(y<47) { |
tim008 | 1:441a9c43ffda | 107 | y++; |
tim008 | 1:441a9c43ffda | 108 | } |
tim008 | 1:441a9c43ffda | 109 | } |
tim008 | 2:f923d0ef12ec | 110 | |
tim008 | 1:441a9c43ffda | 111 | //saranje |
tim008 | 1:441a9c43ffda | 112 | postaviKursor(x,y); |
tim008 | 1:441a9c43ffda | 113 | if(taster1==1) { |
tim008 | 1:441a9c43ffda | 114 | if(displej.getPixel(x,y) == '0') |
tim008 | 1:441a9c43ffda | 115 | displej.setPixel(x,y); |
tim008 | 1:441a9c43ffda | 116 | else displej.clearPixel(x,y); |
tim008 | 1:441a9c43ffda | 117 | } |
tim008 | 2:f923d0ef12ec | 118 | |
tim008 | 1:441a9c43ffda | 119 | //prenos na racunar |
tim008 | 2:f923d0ef12ec | 120 | if(pc.readable() == 1) { |
tim008 | 2:f923d0ef12ec | 121 | if(pc.getc() == 'x') { |
tim008 | 2:f923d0ef12ec | 122 | for(int i=0; i<84; i++) { |
tim008 | 2:f923d0ef12ec | 123 | for(int j=0; j<48; j++) { |
tim008 | 2:f923d0ef12ec | 124 | displej.setXYAddress(0,0); |
tim008 | 2:f923d0ef12ec | 125 | if(displej.getPixel(i, j) == 0) |
tim008 | 2:f923d0ef12ec | 126 | pc.putc('0'); |
tim008 | 2:f923d0ef12ec | 127 | else if (displej.getPixel(i, j)==1) pc.putc('1'); |
tim008 | 2:f923d0ef12ec | 128 | else pc.putc('1'); |
tim008 | 2:f923d0ef12ec | 129 | } |
tim008 | 1:441a9c43ffda | 130 | } |
tim008 | 2:f923d0ef12ec | 131 | pc.putc('\n'); |
tim008 | 1:441a9c43ffda | 132 | } |
tim008 | 2:f923d0ef12ec | 133 | } |
tim008 | 0:24887104b8f0 | 134 | displej.refresh(); |
tim008 | 0:24887104b8f0 | 135 | } |
tim008 | 2:f923d0ef12ec | 136 | |
tim008 | 1:441a9c43ffda | 137 | } |