Ilvana Brankovic Muris Nuhodzic

Dependencies:   N5110 mbed

main.cpp

Committer:
tim008
Date:
2014-04-24
Revision:
0:6576c19bdaf8

File content as of revision 0:6576c19bdaf8:

#include "mbed.h"
#include "N5110.h"


//GLOBALNE VARIJABLE-TACKE 4 KOJE POMJERAN CROSSHAIR
int x1=0;
int x2=1;
int x3=2;
int x4=1;

int y1=1;
int y2=0;
int y3=1;
int y4=2;

int kliknuta=0;

AnalogIn VRx(dp11);
AnalogIn VRy(dp10);

InterruptIn taster1(dp1);
DigitalIn SW(dp17);

DigitalOut enable(dp14);

N5110 lcd(dp4,dp24,dp23,dp25,dp2,dp6,dp18);

//sluzi da vidim da li je paran il neparan u koju da smjestim tacku dijagonale p1 il p2
int i=0;

//TACKE DIJAGONALEEE
int xp1=0;
int yp1=0;

int xp2=0;
int yp2=0;

int kliknuta1=0;

// TASTERR1-vidi sta se desavaa da li printString il setpixel
void pomocna()
{
    if(i%2==0)
    {
    kliknuta=1;
    xp1=x2;
    yp1=y1;
    }
    else
    {
        kliknuta1=1;
        xp2=x2;
        yp2=y1;
    }
    i++;
    //lcd.printString(".",x2,y1);
}
int main() 
{
    lcd.init();
    taster1.rise(&pomocna);
    lcd.setXYAddress(0,0);
    while(1) {
    lcd.setPixel(x1,y1);
    lcd.setPixel(x2,y2);
    lcd.setPixel(x3,y3);
    lcd.setPixel(x4,y4);
    lcd.refresh();
        
        if(VRx<1.0/3.0)   //POMJERAAA LIJEVOOO-pazii je kraj ekranaaa
        {
            if(x1!=1 && x2!=2 && x3!=3 && x4!=2)
            {
            lcd.clearPixel(x1,y1);
            lcd.clearPixel(x2,y2);
            lcd.clearPixel(x3,y3);
            lcd.clearPixel(x4,y4);
            
            x1--;
            x2--;
            x3--;
            x4--;
            lcd.setPixel(x1,y1);
            lcd.setPixel(x2,y2);
            lcd.setPixel(x3,y3);
            lcd.setPixel(x4,y4);
            if(kliknuta==1) 
            lcd.setPixel(xp1,yp1);
            if(kliknuta1==1)
            lcd.setPixel(xp2,yp2);
            lcd.refresh();
            wait(0.5);
            }
        }
        
        if(VRx>2.0/3.0)// pomjeraaaa desnoo, pazii kraj ekraaana 84 piksela
        {
             if(x1!=84 && x2!=84 && x3!=84 && x4!=84)
            {
                //if( x1!=xp1 && x2!=xp2 && x3!=xp1 &&  x4!=xp1 && y1!=yp1 && y2!=yp1 && y3!=yp1 && y4!=yp1)
                
            lcd.clearPixel(x1,y1);
            lcd.clearPixel(x2,y2);
            lcd.clearPixel(x3,y3);
            lcd.clearPixel(x4,y4);
            
            
            x1++;
            x2++;
            x3++;
            x4++;
            lcd.setPixel(x1,y1);
            lcd.setPixel(x2,y2);
            lcd.setPixel(x3,y3);
            lcd.setPixel(x4,y4);
             if(kliknuta==1) 
            lcd.setPixel(xp1,yp1);
            if(kliknuta1==1)
            lcd.setPixel(xp2,yp2);
            lcd.refresh();
            wait(0.5);
            }
        }
        if(VRy<1.0/3.0)// pomjeraaa doljeeee max 48
        {
            if(y1!=2 && y2!=1 && y3!=2 && y4!=3)
             {
            //if( x1!=xp1 && x2!=xp2 && x3!=xp1 &&  x4!=xp1 && y1!=yp1 && y2!=yp1 && y3!=yp1 && y4!=yp1)
            
            lcd.clearPixel(x1,y1);
            lcd.clearPixel(x2,y2);
            lcd.clearPixel(x3,y3);
            lcd.clearPixel(x4,y4);
            
            
            y1--;
            y2--;
            y3--;
            y4--;
             lcd.setPixel(x1,y1);
             lcd.setPixel(x2,y2);
             lcd.setPixel(x3,y3);
             lcd.setPixel(x4,y4);
              if(kliknuta==1) 
            lcd.setPixel(xp1,yp1);
            if(kliknuta1==1)
            lcd.setPixel(xp2,yp2);
             lcd.refresh();
             wait(0.5);
             }
        }
        if(VRy>2.0/3.0)/// pomjeraaa goreeeee paziii 48 ogranicenjeee
        {
            if(x1!=48 && x2!=48 && x3!=48 && x4!=48)
            {
            //if( x1!=xp1 && x2!=xp2 && x3!=xp1 &&  x4!=xp1 && y1!=yp1 && y2!=yp1 && y3!=yp1 && y4!=yp1)
            
            lcd.clearPixel(x1,y1);
            lcd.clearPixel(x2,y2);
            lcd.clearPixel(x3,y3);
            lcd.clearPixel(x4,y4);
            
            y1++;
            y2++;
            y3++;
            y4++;
             lcd.setPixel(x1,y1);
             lcd.setPixel(x2,y2);
             lcd.setPixel(x3,y3);
             lcd.setPixel(x4,y4);
            if(kliknuta==1) 
            lcd.setPixel(xp1,yp1);
            if(kliknuta1==1)
            lcd.setPixel(xp2,yp2);
             lcd.refresh();
             wait(0.5);
             }        
    }
  
    if(xp1!=0 && xp2!=0 && yp1!=0 && yp2!=0)// pravougaonikkkkkk 4 slucajaaa 
    {
       if(xp1<xp2 && yp1<yp2)// GLOBALNE VARIJABLEEE
       {
           for(int i=yp1;i<=yp2;i++)
           {
               for(int j=xp1;j<=xp2;j++)
               {
                   lcd.setPixel(i,j);
                   }
            }
       }
       if(xp1>xp2 && yp1>yp2)
       {
            for(int i=yp2;i<=yp1;i++)
           {
               for(int j=xp2;j<=xp1;j++)
               {
                   lcd.setPixel(i,j);
                   }
            }
        }
        if(xp1>xp2 && yp2>yp1)
        {
             for(int i=yp1;i<=yp2;i++)
           {
               for(int j=xp2;j<=xp1;j++)
               {
                   lcd.setPixel(i,j);
                   }
            }
        }
        //postavim ih sad na nulu da moze iduci pravougaonik da iscrta ///
       
    
    }
    }
    }