tim007 tim007
/
LV7-Grupa1-Tim007-Zadatak1
Emir Djenasevic Azra Jarebica
Fork of LV7_Grupa4_Tim007 by
main.cpp
- Committer:
- tim007
- Date:
- 2014-04-28
- Revision:
- 0:be75535cf4b1
- Child:
- 1:f6c556b8e9e0
File content as of revision 0:be75535cf4b1:
#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); int X,Y, VIx, VIy; int px, py, pvx, pvy; int brojac = 0; DigitalOut enable(dp14); void crtaj() { //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.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() { 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--; */ } int main() { 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) { update(); timer.reset(); timer.start(); } if(t2.read_ms() > 500) { updateViljuska(); t2.reset(); t2.start(); } lcd.setXYAddress(0,0); crtaj(); } }