Haskovic Nedzad Klacar Armin

Dependencies:   N5110 mbed

Revision:
0:6c9a905cf074
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Apr 24 15:59:35 2014 +0000
@@ -0,0 +1,120 @@
+#include "mbed.h"
+#include "N5110.h"
+  
+//Analogni ulazi sa dzojstika
+AnalogIn    VRx(dp11);
+AnalogIn    VRy(dp10);
+//Taster sa dzojstika
+DigitalIn   SW(dp17);
+//Deklaracija LCD objekta
+//N5110 lcd(VCC,SCE,RST,D/C,MOSI,SCLK,LED)
+N5110 lcd(dp4,dp24,dp23,dp25,dp2,dp6,dp18);
+ 
+//Digitalni izlaz za deaktivaciju LED buffera
+DigitalOut enable(dp14);
+
+void baklava(int x, int y){
+    lcd.clear();
+    lcd.refresh();
+    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+1,y+1);
+    lcd.setPixel(x-1,y+1);
+    lcd.setPixel(x,y+2);
+    lcd.setPixel(x,y-1);
+    lcd.setPixel(x+1,y-1);
+    lcd.setPixel(x-1,y-1);
+    lcd.setPixel(x,y-2);
+    lcd.refresh();
+}
+
+void viljuska(int x,int y) {
+    lcd.refresh();
+    lcd.setPixel(x,y);
+    lcd.setPixel(x+1,y);
+    lcd.setPixel(x-1,y);
+    lcd.setPixel(x,y+1);
+    lcd.setPixel(x,y+2);
+    lcd.setPixel(x,y-1);
+    lcd.setPixel(x+2,y-1);
+    lcd.setPixel(x-2,y-1);
+    lcd.refresh();
+    
+    
+    }
+int main()
+{
+    enable=1;
+ static int x(0),y(0);
+ static int i(0),j(0);
+    // inicijalizacija displeja
+    lcd.init();
+    lcd.setXYAddress(0,0);
+    SW.mode(PullUp);
+ int a[10]={4,5,6,7,8,9,10,11,12,13};
+  int b[10]={3,4,5,6,7,8,9,10,11,12};
+     while(1)
+    {   
+     if (VRx<1.0/3.0) 
+     {
+         x=x-3;
+     baklava(x,y); 
+     ++i;
+     if(i>9) i=9;
+     viljuska(x+a[i],y+b[j]);
+    }
+     else if (VRx<2.0/3.0) 
+    {
+    baklava(x,y); 
+    if(i>9) i=9;
+    viljuska(x+a[i],y+b[j]);
+    }
+    else 
+    {x=x+3;
+    baklava(x,y);
+    ++i;
+    if(i>9) i=9;
+    viljuska(x+a[i],y+b[j]); }
+    wait(0.05);
+    
+    if (VRy<1.0/3.0) 
+     {
+      y=y-3;
+      baklava(x,y); 
+      ++j;
+      if(j>9) j=9;
+     viljuska(x+a[i],y+b[j]);
+ 
+    }
+     else if (VRy<2.0/3.0) 
+    {
+    baklava(x,y); 
+    if(j>9) j=9;
+    viljuska(x+a[i],y+b[j]);
+  
+    }  
+    else    
+    {
+     y=y+3;
+     baklava(x,y); 
+     ++j;
+    if(j>9) j=9;
+    viljuska(x+a[i],y+b[j]);
+    }
+    
+    if (VRx<2.0/3.0 && VRy<2.0/3.0){
+           baklava(x,y); 
+           --i;
+           --j;
+           if (i<0) i=0;
+           if (j<0) j=0;
+    viljuska(x+a[i],y+b[j]);
+       } 
+       wait(0.05); 
+    }
+}
+  
\ No newline at end of file