tim010 tim010
/
Projekat15_pai_grupa6_tim010
Hadžić Muharem Mousavi Maedeh
main.cpp
- Committer:
- tim010
- Date:
- 2014-06-09
- Revision:
- 0:0a484beeccaf
File content as of revision 0:0a484beeccaf:
#include "mbed.h" #include "N5110.h" #include "PS2Mouse.h" //N5100 ekran(VCC,SCE,RST,D/C,MOSI,SCLK,LED) N5110 ekran(dp4,dp24,dp23,dp25,dp2,dp6,dp18); //CLKpin, DATApin PS2Mouse mis(dp10, dp11); PS2Mouse::mouse_event_t event; int x=42,y=24; int x1=x,y1=y; int X,Y; int pomX=0,pomY=0,brojac=0; bool crtaj=false,brisi=true; void nacrtaj_pom(int a,int b,int d1,int d2){ for(int i=0;i<=d1;i++){ for(int j=0;j<=d2;j++){ if(i==0||j==0||i==d1||j==d2){ ekran.setPixel(a+i,b+j); } } } ekran.refresh(); } void ocistiEkran(){ ekran.clear(); crtaj=false; brisi=true; } void pomjeranjeMisa(){ if(x<0||x>83||y<0||y>47){ if(x<0) x=0; if(x>83) x=83; if(y<0) y=0; if(y>47) y=47; return; } char znak=ekran.getPixel(x,y); if(znak!=0){ return; } if(brisi){ ekran.clearPixel(x1,y1); } brisi=true; ekran.setPixel(x,y); x1=x; y1=y; ekran.refresh(); } void oznaci(int a,int b){ ekran.setPixel(a,b); ekran.refresh(); crtaj=true; brisi=false; } void nacrtaj(int a,int b){ int d1=a-X; if(d1<0) d1=-d1; int d2=b-Y; if(d2<0) d2=-d2; int k1,k2; if(a<X){ k1=a; } else{ k1=X; } if(b<Y){ k2=b; } else{ k2=Y; } nacrtaj_pom(k1,k2,d1,d2); crtaj=false; brisi=false; } DigitalOut enable(dp14); int main() { enable=1; ekran.init(); ekran.setXYAddress(0,0); pomjeranjeMisa(); while(1) { if (mis.processing(&event)) { pomX+=event.x; pomY+=event.y; brojac++; if(brojac==3){ if(pomX>0){ x+=1; } else{ x-=1; } if(pomY>0){ y-=1; } else{ y+=1; } pomjeranjeMisa(); pomX=pomY=brojac=0; } if (event.left){ if(!crtaj){ X=x; Y=y; oznaci(X,Y); } else{ nacrtaj(x,y); } } if (event.right){ ocistiEkran(); } } } }