Amra Dautbegović Luka Pejović

Dependencies:   N5110 mbed

Files at this revision

API Documentation at this revision

Comitter:
tim007
Date:
Mon May 05 07:03:24 2014 +0000
Parent:
0:be75535cf4b1
Commit message:
LV7-PAI-Grupa1-Tim007

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r be75535cf4b1 -r f6c556b8e9e0 main.cpp
--- a/main.cpp	Mon Apr 28 17:50:51 2014 +0000
+++ b/main.cpp	Mon May 05 07:03:24 2014 +0000
@@ -1,168 +1,119 @@
 #include "mbed.h"
 #include "N5110.h"
  
-AnalogIn VRx (dp11);
-AnalogIn VRy (dp10);
-class Ekran: public N5110
-{
-    public:
-   
-    void setPixel(int x, int y)
-    {
-        if(x < 0 || x > 83)
-            return;
-        if(y < 0 || y > 47)
-            return;
-            
-        N5110::setPixel(x,y); 
-    }
-};
-N5110 lcd (dp13 ,dp24 ,dp23 ,dp25 ,dp2 ,dp6 , dp18);
-
+//Analogni ulazi sa dzojstika
+AnalogIn    VRx(dp11);
+AnalogIn    VRy(dp10);
+//Taster sa dzojstika
+DigitalIn   SW(dp9);
+//Deklaracija LCD objekta
+N5110 lcd(dp4,dp24,dp23,dp25,dp2,dp6,dp18);
  
-int X,Y, VIx, VIy;
-
-int px, py, pvx, pvy;
-int brojac = 0;
+//Digitalni izlaz za deaktivaciju LED buffera
 DigitalOut enable(dp14);
-
-
-
-    
-    
-
-void crtaj()
+ 
+void baklava(int x, int y)
 {
-    //clear baklava
-    lcd.clearPixel(px, py);
-    lcd.clearPixel(px+1, py);
-    lcd.clearPixel(px+2, py);
-    lcd.clearPixel(px-1, py);
-    lcd.clearPixel(px-2, py);
-    lcd.clearPixel(px, py+1);
-    lcd.clearPixel(px, py+2);
-    lcd.clearPixel(px, py-1);
-    lcd.clearPixel(px, py-2);
-    lcd.clearPixel(px+1, py+1);
-    lcd.clearPixel(px+1, py-1);
-    lcd.clearPixel(px-1, py-1);
-    lcd.clearPixel(px-1, py+1);
-    
-    px = X;
-    py = Y;
-    //crtaj baklava
-    lcd.setPixel(X, Y);
-    lcd.setPixel(X+1, Y);
-    lcd.setPixel(X+2, Y);
-    lcd.setPixel(X-1, Y);
-    lcd.setPixel(X-2, Y);
-    lcd.setPixel(X, Y+1);
-    lcd.setPixel(X, Y+2);
-    lcd.setPixel(X, Y-1);
-    lcd.setPixel(X, Y-2);
-    lcd.setPixel(X+1, Y+1);
-    lcd.setPixel(X+1, Y-1);
-    lcd.setPixel(X-1, Y-1);
-    lcd.setPixel(X-1, Y+1);
-    
-    //clear viljuska
-    lcd.clearPixel(pvx-3, pvy-3);
-    lcd.clearPixel(pvx-3, pvy-4);
-    lcd.clearPixel(pvx-3, pvy-5);
-    lcd.clearPixel(pvx-4, pvy-6);
-    lcd.clearPixel(pvx-5, pvy-3);
-    lcd.clearPixel(pvx-5, pvy-4);
-    lcd.clearPixel(pvx-5, pvy-5);
-    lcd.clearPixel(pvx-5, pvy-6);
-    lcd.clearPixel(pvx-5, pvy-7);
-    lcd.clearPixel(pvx-5, pvy-8);
-    lcd.clearPixel(pvx-5, pvy-9);
-    lcd.clearPixel(pvx-5, pvy-10);
-    lcd.clearPixel(pvx-6, pvy-6);
-    lcd.clearPixel(pvx-7, pvy-5);
-    lcd.clearPixel(pvx-7, pvy-4);
-    lcd.clearPixel(pvx-7, pvy-3);
-    
-    pvx = VIx;
-    pvy = VIy;
-    //viljuska
-    lcd.setPixel(VIx-3, VIy-3);
-    lcd.setPixel(VIx-3, VIy-4);
-    lcd.setPixel(VIx-3, VIy-5);
-    lcd.setPixel(VIx-4, VIy-6);
-    lcd.setPixel(VIx-5, VIy-3);
-    lcd.setPixel(VIx-5, VIy-4);
-    lcd.setPixel(VIx-5, VIy-5);
-    lcd.setPixel(VIx-5, VIy-6);
-    lcd.setPixel(VIx-5, VIy-7);
-    lcd.setPixel(VIx-5, VIy-8);
-    lcd.setPixel(VIx-5, VIy-9);
-    lcd.setPixel(VIx-5, VIy-10);
-    lcd.setPixel(VIx-6, VIy-6);
-    lcd.setPixel(VIx-7, VIy-5);
-    lcd.setPixel(VIx-7, VIy-4);
-    lcd.setPixel(VIx-7, VIy-3);
-    
+    lcd.clear();
+    lcd.setPixel(x,y);
+    lcd.setPixel(x+1, y);
+    lcd.setPixel(x+2, y);
+    lcd.setPixel(x-1, y);
+    lcd.setPixel(x-2, y);
+    lcd.setPixel(x, y+1);
+    lcd.setPixel(x, y+2);
+    lcd.setPixel(x, y-1);
+    lcd.setPixel(x,y-2);
+    lcd.setPixel(x+1,y+1);
+    lcd.setPixel(x-1,y+1);
+    lcd.setPixel(x-1,y-1);
+    lcd.setPixel(x+1,y-1);
     lcd.refresh();
 }
-
-void update(){
-    
-    if (VRx<1.0/3.0){
-        if(X >= 9)X--;
-    }
-    else if (VRx > 2.0/3.0){
-        if( X <= 78)X++;
-    }
-    
-    if (VRy<1.0/3.0){
-        if(Y >= 12)Y--;
-    }
-    else if (VRy > 2.0/3.0){
-        if( Y <= 42)Y++;
-    }
-    
-    
-}
-
-void updateViljuska()
+ 
+void viljuska(int x, int y)
 {
-    VIx = (VIx - X)*2/3 + X;
-    VIy = (VIy - Y)*2/3 + Y;
-    /*
-    if(X > VIx) VIx++;
-    else if( X < VIx) VIx--;
-    
-    if(Y > VIy) VIy++;
-    else if(Y < VIy) VIy--; */
+   
+    lcd.setPixel(x+7,y+1);
+    lcd.setPixel(x+5,y+2);
+    lcd.setPixel(x+4,y+3);
+    lcd.setPixel(x+5,y+4);
+    lcd.setPixel(x+3,y+3);
+    lcd.setPixel(x+2,y+4);
+    lcd.setPixel(x+4,y+5);
+    lcd.setPixel(x+1,y+5);
+    lcd.setPixel(x+3,y+6);
+    lcd.refresh();
 }
  
 int main()
 {
-    enable = 1;
-    
+    enable=1;
     lcd.init();
-    
-    lcd.clear();
-    Timer timer, t2;
-    timer.start();
-    t2.start();
-    VIx = VIy = X = Y = 24;
-    
-    while(1) {
-        if(timer.read_ms() > 100)
+    lcd.setXYAddress(0,0);
+    int x=0, y=0;
+    baklava(x+3,y+3);
+    int i=0;
+    bool pomjeriX=false, pomjeriY=false;  
+   int niz[20] = {4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
+    while(1)
+    {
+        if (VRx<1.0/3.0) 
+        {   
+            if(x>3)
+            {
+                pomjeriX = true;
+                x=x-1;
+            }
+            baklava(x+niz[i],y+niz[i]);
+            viljuska(x,y);
+        }
+        else if(VRx<2.0/3.0)
+        {
+            pomjeriX = false;
+            baklava(x+niz[i],y+niz[i]);
+            viljuska(x,y);
+        }
+        else
         {
-            update();
-            timer.reset();
-            timer.start();
+            if(x<80)
+            {
+                pomjeriX=true;
+                x=x+1;
+            }
+            baklava(x+niz[i],y+niz[i]);
+            viljuska(x,y);
         }
-        if(t2.read_ms() > 500)
+        if (VRy<1.0/3.0) 
+        {
+            if(y>3)
+            {
+                pomjeriY = true;
+                y=y-1;
+            }
+            baklava(x+niz[i],y+niz[i]);
+            viljuska(x,y);
+        }
+        else if(VRy<2.0/3.0)
         {
-            updateViljuska();
-            t2.reset();
-            t2.start();   
+            pomjeriY=false;
+            baklava(x+niz[i],y+niz[i]);
+            viljuska(x,y);
         }
-        lcd.setXYAddress(0,0);
-        crtaj();
+        else
+        {
+            if(y<45)
+            {
+                pomjeriY=true;
+                y=y+1;
+            }
+            baklava(x+niz[i],y+niz[i]);
+            viljuska(x,y);
+        }
+        bool kretaoSe=false;
+        if(pomjeriX==true || pomjeriY==true) kretaoSe=true;
+        if(kretaoSe && i<19) i++;
+        else if (kretaoSe==false && i>0) i--;
+        wait_ms(100);
     }
 }
\ No newline at end of file