Goro Faruk Predrag Simanić

Dependencies:   N5110 mbed

Revision:
0:4a555e5d13e6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 26 16:01:11 2014 +0000
@@ -0,0 +1,204 @@
+#include "mbed.h"
+#include "N5110.h"
+ 
+#define MAXWIDTH 84
+#define MAXHEIGHT 48
+ 
+Timer t;
+DigitalOut enable(dp14);
+ int X1=7,X2=73;int Y=20;
+ int x1=90,y1=90,x2,y2;
+ 
+int x=30,y=30;
+AnalogIn VRy2(dp11);
+AnalogIn VRy1(dp10);
+DigitalIn SW1(dp9), SW2(dp13);
+
+N5110 lcd (dp4, dp24, dp23, dp25, dp2, dp6, dp18);
+ 
+int l=1; 
+void palija1(int x, int y)
+{
+    int i=7;
+    if(y>6 && y<33)
+     for(int j=y; j<=y+2; j++)
+    {
+        lcd.clearPixel(i,j-1);
+        lcd.setPixel(i,j);
+        lcd.setPixel(i,j+1);
+        lcd.setPixel(i,j+2);
+        lcd.setPixel(i,j+3);
+        lcd.clearPixel(i,j+4);
+        lcd.refresh();
+    }
+}
+ 
+void palija2(int x, int y)
+{
+    int i=73;
+    if(y>6 && y<33)
+     for(int j=y; j<=y+2; j++)
+    {   
+    lcd.clearPixel(i,j-1);
+        lcd.setPixel(i,j);
+        lcd.setPixel(i,j+1);
+        lcd.setPixel(i,j+2);
+        lcd.setPixel(i,j+3);
+        lcd.clearPixel(i,j+4);
+        lcd.refresh();
+    }
+}
+ 
+void Teren()
+{
+    lcd.setXYAddress(0,0);
+     int j =5;
+     for(int i =5;i<= 75;i++)
+     {
+        lcd.setPixel(i,j);
+        lcd.refresh();
+     }   
+     int k=75;
+     for(int i=5;i<=40;i++) 
+     {
+        lcd.setPixel(k,i);
+        lcd.refresh();
+     }
+     j=40;
+     for(int i =75;i>=5;i--)
+     {
+       lcd.setPixel (i,j);
+       lcd.refresh();
+      
+     }
+     
+     k=5;
+     for(int i = 40; i>= 5;i--)
+     {
+       lcd.setPixel(k,i);
+       lcd.refresh();
+      
+      }
+     
+     j=40;
+     for(int i=5;i<=40;i++)
+     {
+       lcd.setPixel(j,i);
+       lcd.refresh();
+      
+     }
+    
+}
+
+void Gore(int &x, int &y)
+{
+    if(y>0)
+    {
+       lcd.clearPixel(x,y+1);
+        y=y-1;
+       
+      
+    }
+}
+ 
+void Dole(int &x, int &y)
+{
+    if(y<33)
+    {
+        lcd.clearPixel(x,y-1);
+        y=y+1;
+        
+    }
+}
+ 
+void kretanjeLoptice()
+{
+    if (l==1)
+    {
+        while (x!=8)
+        {
+            x--;
+            lcd.setPixel(x,y);
+            lcd.setPixel(x,y+1);
+            lcd.setPixel(x+1,y);
+            lcd.setPixel(x+1,y+1);
+            lcd.clearPixel(x+2,y);
+            lcd.clearPixel(x+2,y+1);
+            lcd.refresh();
+            wait(0.05);
+        }
+        l=0;
+    }
+    if (l==0)
+    {
+    while (x!=72)
+    {
+        x++;
+        lcd.setPixel(x,y);
+        lcd.setPixel(x,y+1);
+        lcd.setPixel(x+1,y);
+        lcd.setPixel(x+1,y+1);
+        lcd.clearPixel(x-2,y);
+        lcd.clearPixel(x-2,y+1);
+        lcd.refresh();
+        wait(0.05);
+    }
+    l=1;
+    x=72;
+    }
+
+    
+
+}
+ 
+void loptica()
+{
+     lcd.setPixel(30,30);
+     lcd.setPixel(31,31);
+     lcd.setPixel(30,31);
+     lcd.setPixel(31,30);
+     lcd.refresh();
+}
+ 
+int main()
+{
+  lcd.setXYAddress(0,0);
+  enable = 1;
+  SW1.mode(PullUp);
+  SW2.mode(PullUp);
+  t.start();
+  lcd.init();
+  Teren();
+  palija1(X1,Y);
+  loptica();
+  palija2(X2,Y);
+  while(1){
+      kretanjeLoptice();
+      if(VRy1 < 1.0/3.0) 
+      {
+          lcd.refresh();
+          Gore(X1,Y);
+          palija1(X1,Y);
+      }
+      else if(VRy1 > 2.0/3.0) 
+      {
+          lcd.refresh();
+          Dole(X1,Y);
+          palija1(X1,Y);
+        }
+      
+      if(VRy2 < 1.0/3.0) 
+      {
+          lcd.refresh();
+          Gore(X2,Y);
+          palija2(X2,Y);
+          }
+      else if(VRy2 > 2.0/3.0) 
+      {
+          lcd.refresh();
+          Dole(X2,Y);
+          palija2(X2,Y);
+      }
+  }
+}
+     
\ No newline at end of file