Haris Šemić, Emina Šarić

Dependencies:   N5110 mbed

Revision:
2:f923d0ef12ec
Parent:
1:441a9c43ffda
Child:
3:27c6c5d1fe5f
--- a/main.cpp	Thu Jun 05 14:13:17 2014 +0000
+++ b/main.cpp	Thu Jun 12 13:09:51 2014 +0000
@@ -9,30 +9,39 @@
 AnalogIn VRy(dp10);
 
 DigitalIn taster1(dp1);
-DigitalIn taster2(dp2);
+//DigitalIn taster2(dp2);
 
 DigitalIn SW(dp9);
-DigitalOut enable(dp14);
 
-char detektirajPozadinu(int x, int y) {
+char detektirajPozadinu(int x, int y)
+{
     if(x>83 || x<0 || y>47 || y<0) return 'x';
     int brRubnih(0), brCrnih(0);
     unsigned char gore,dole,lijevo,desno;
-    if(x == 0) lijevo = 'x'; else lijevo = displej.getPixel(x-1,y);
-    if(x == 83) desno = 'x'; else desno = displej.getPixel(x+1,y);
-    if(y == 0) dole = 'x'; else dole = displej.getPixel(x,y-1);
-    if(y == 47) gore = 'x'; else gore = displej.getPixel(x,y+1);
-    if(lijevo == '0') brCrnih++; else if(lijevo == 'x') brRubnih++;
-    if(desno == '0') brCrnih++; else if(desno == 'x') brRubnih++;
-    if(gore == '0') brCrnih++; else if(gore == 'x') brRubnih++;
-    if(dole == '0') brCrnih++; else if(dole == 'x') brRubnih++;
+    if(x == 0) lijevo = 'x';
+    else lijevo = displej.getPixel(x-1,y);
+    if(x == 83) desno = 'x';
+    else desno = displej.getPixel(x+1,y);
+    if(y == 0) dole = 'x';
+    else dole = displej.getPixel(x,y-1);
+    if(y == 47) gore = 'x';
+    else gore = displej.getPixel(x,y+1);
+    if(lijevo == '0') brCrnih++;
+    else if(lijevo == 'x') brRubnih++;
+    if(desno == '0') brCrnih++;
+    else if(desno == 'x') brRubnih++;
+    if(gore == '0') brCrnih++;
+    else if(gore == 'x') brRubnih++;
+    if(dole == '0') brCrnih++;
+    else if(dole == 'x') brRubnih++;
     int brBijelih(4-brCrnih-brRubnih);
     if(brBijelih < brCrnih) return 'c';
     return 'b';
 }
 
-void postaviKursor(int x, int y) {
-    for(int i(1);i<5;i++) {
+void postaviKursor(int x, int y)
+{
+    /*for(int i(1); i<5; i++) {
         char pozadina(detektirajPozadinu(x+i, y));
         if(pozadina == 'b')
             displej.setPixel(x+i,y);
@@ -49,50 +58,56 @@
         if(pozadina == 'b')
             displej.setPixel(x,y-i);
         else if(pozadina == 'c') displej.clearPixel(x,y-i);
-    }
+    }*/
+    displej.setPixel(x,y);
+    wait(0.01);
 }
 
-int main() {
-    enable=1;
+int main()
+{
     SW.mode(PullUp);
     displej.init();
     displej.setXYAddress(0,0);
-    int x(0),y(0);    
+    int x(0),y(0);
     pc.baud(115200);
-    while(1) {                
-        for(int i=0; i<84; i++) {
-         for(int j=0; j<48; j++) {            
+    for(int i=0; i<84; i++) {
+        for(int j=0; j<48; j++) {
             if(pc.getc()=='1') {
                 displej.setXYAddress(0,0);
-                displej.setPixel(i,j);                              
-                }
+                displej.setPixel(i,j);
             }
         }
-        
-        if(VRx<1.0/3.0) {    
+    }
+    while(1) {
+        /*    if(pc.readable() == 1) {
+                if(pc.getc() != 'x') {
+
+                }
+            }        */
+        if(VRx<1.0/3.0) {
             if (x>0) {
                 x--;
             }
-        }       
-        
+        }
+
         else if (VRx>2.0/3.0) {
             if(x<83) {
-                x++;  
+                x++;
             }
-        }      
-        
+        }
+
         if (VRy<1.0/3.0) {
             if(y>0) {
                 y--;
             }
         }
-                
+
         else if (VRy>2.0/3.0) {
             if(y<47) {
                 y++;
             }
         }
-        
+
         //saranje
         postaviKursor(x,y);
         if(taster1==1) {
@@ -100,17 +115,23 @@
                 displej.setPixel(x,y);
             else displej.clearPixel(x,y);
         }
-        
+
         //prenos na racunar
-        if(pc.getc() == 'x') {
-            for(int i=0; i<84; i++) {
-                for(int j=0; j<48; j++) {            
-                    if(displej.getPixel(i, j) == '0')
-                        pc.putc('0');
-                    else pc.putc('1');
+        if(pc.readable() == 1) {
+            if(pc.getc() == 'x') {
+                for(int i=0; i<84; i++) {
+                    for(int j=0; j<48; j++) {
+                        displej.setXYAddress(0,0);
+                        if(displej.getPixel(i, j) == 0)
+                            pc.putc('0');
+                        else if (displej.getPixel(i, j)==1) pc.putc('1');
+                        else pc.putc('1');
+                    }
                 }
+                pc.putc('\n');
             }
-        }       
+        }
         displej.refresh();
     }
+
 }
\ No newline at end of file