Lejla Agić Zlatan Čilić

Dependencies:   N5110 mbed

Files at this revision

API Documentation at this revision

Comitter:
tim004
Date:
Mon May 05 07:44:21 2014 +0000
Commit message:
LV7_grupa1_PAI_tim004

Changed in this revision

N5110.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/N5110.lib	Mon May 05 07:44:21 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/eencae/code/N5110/#adb79338d40f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 05 07:44:21 2014 +0000
@@ -0,0 +1,203 @@
+#include "mbed.h"
+#include "N5110.h"
+
+InterruptIn taster1(dp1);
+AnalogIn VRx(dp11);
+AnalogIn VRy(dp10);
+N5110 lcd(dp4,dp24,dp23,dp25,dp2,dp6,dp18);
+const double unitX(3.3/84.0);
+const double unitY(3.3/48.0);
+int brojac(0);
+int trenX(42);
+int trenY(24);
+Timer debounce;
+int prvaX(0);
+int prvaY(0);
+bool postavljena(false);
+
+void postaviKockicu(int x, int y)
+{
+    //if(x > 47 || x < 1 || y < 1 || y > 83) return;
+    //else
+    //{
+        
+        lcd.setXYAddress(0,0);
+        lcd.setPixel(x-1, y-1);
+        lcd.setXYAddress(0,0);
+        //lcd.refresh();  
+        lcd.setXYAddress(0,0);
+        lcd.setPixel(x-1, y);
+        //lcd.refresh();   
+          lcd.setXYAddress(0,0);
+        lcd.setPixel(x-1, y+1);
+        //lcd.refresh();  
+         lcd.setXYAddress(0,0);
+        lcd.setPixel(x, y-1);
+        //lcd.refresh();
+          lcd.setXYAddress(0,0);
+        lcd.setPixel(x, y);
+       // lcd.refresh();
+          lcd.setXYAddress(0,0);
+        lcd.setPixel(x, y+1);
+       // lcd.refresh();
+          lcd.setXYAddress(0,0);
+        lcd.setPixel(x+1, y-1);
+        //lcd.refresh(); 
+         lcd.setXYAddress(0,0);
+        lcd.setPixel(x+1, y);
+       // lcd.refresh();
+         lcd.setXYAddress(0,0);
+        lcd.setPixel(x+1, y+1);
+          lcd.setXYAddress(0,0);
+        lcd.refresh();
+    //}
+}
+
+void ocitajDzojstik()
+{
+    
+    //float a = VRx / unitX;
+    //float b = VRy / unitY;
+    //setXYAdress(0,0);
+    if(VRx > 2.0/3.0)
+    {
+        if(trenX >= 83) return;
+        trenX++;
+    }
+    if(VRx < 1.0/2.0) 
+    {
+        if(trenX <= 1) return;
+        trenX--;
+    }
+ 
+    if(VRy > 2.0/3.0)
+    {
+        if(trenY >= 47) return;
+        trenY++;
+    }
+    if(VRy < 1.0/3.0) 
+    {
+        if(trenY <= 1) return;
+        trenY--;
+    }  
+}
+
+void iscrtajLiniju(int x0, int y0, int x1, int y1)
+{
+   
+    int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
+    int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1; 
+    int err = (dx>dy ? dx : -dy)/2, e2;
+ 
+  for(;;){
+    lcd.setXYAddress(0,0);
+    lcd.setPixel(x0,y0);
+    lcd.setXYAddress(0,0);
+    lcd.refresh();
+    if (x0==x1 && y0==y1) break;
+    e2 = err;
+    if (e2 >-dx) { err -= dy; x0 += sx; }
+    if (e2 < dy) { err += dx; y0 += sy; }
+  }
+   
+   /* int dx, dy, sx, sy;
+    if(x0 < x1)
+    {
+        dx = x1 - x0;
+        sx = 1;
+    }
+    else
+    {
+        dx = x0 - x1;
+        sx = -1;
+    }
+    if(y0 < y1)
+    {
+        dy = y1 - y0;
+        sy = 1;
+    }
+    else
+    {
+        dy = y0 - y1;
+        sy = -1;
+    }
+    
+    double error = dx - dy;
+    double e2;
+    while(1)
+    {
+        lcd.setPixel(x0, y0);
+        lcd.refresh();
+        if(x0 == x1 && y0 == y1) break;
+        e2 = 2 * error;
+        if(e2 > -dy)
+        {
+            error -=dy;
+            x0 += dx;
+        }
+        if(e2 < dx)
+        {
+            error += dx;
+            y0 += dy;
+        }
+    }*/
+    
+    
+    
+    
+}
+
+void postaviTacku()
+{
+    if(debounce.read_ms() > 400)
+    {
+        if(false == postavljena)
+        {
+            prvaX = trenX;
+            prvaY = trenY;
+            postavljena = true; 
+        }
+        else
+        {
+            //ocitajDzojstik();
+            //lcd.clear();
+            //postaviKockicu(trenX, trenY);
+            //postaviKockicu(prvaX, prvaY);
+            //postaviKockicu(prvaX, prvaY);
+            iscrtajLiniju(trenX, trenY, prvaX, prvaY);
+            wait(5);
+            lcd.clear();
+            postavljena = false;
+            trenX = 42;
+            trenY = 24;
+        }   
+        debounce.reset();
+    }
+}
+
+
+
+int main()
+{
+    lcd.init();
+    postaviKockicu(42,24);
+    debounce.start();
+    taster1.rise(&postaviTacku);
+    
+    while(1)
+    {
+        ocitajDzojstik();
+        if(postavljena == false)
+        {
+            lcd.clear();
+            postaviKockicu(trenX, trenY);
+        }
+        else
+        {
+            lcd.clear();
+            postaviKockicu(trenX, trenY);
+            postaviKockicu(prvaX, prvaY);
+        }
+    }
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 05 07:44:21 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file