Emir Djenasevic Azra Jarebica

Dependencies:   N5110 mbed

Fork of LV7_Grupa4_Tim007 by tim007 tim007

Committer:
tim007
Date:
Mon Apr 28 17:50:51 2014 +0000
Revision:
0:be75535cf4b1
Child:
1:f6c556b8e9e0
LV7-PAI-Grupa4-Tim007;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tim007 0:be75535cf4b1 1 #include "mbed.h"
tim007 0:be75535cf4b1 2 #include "N5110.h"
tim007 0:be75535cf4b1 3
tim007 0:be75535cf4b1 4 AnalogIn VRx (dp11);
tim007 0:be75535cf4b1 5 AnalogIn VRy (dp10);
tim007 0:be75535cf4b1 6 class Ekran: public N5110
tim007 0:be75535cf4b1 7 {
tim007 0:be75535cf4b1 8 public:
tim007 0:be75535cf4b1 9
tim007 0:be75535cf4b1 10 void setPixel(int x, int y)
tim007 0:be75535cf4b1 11 {
tim007 0:be75535cf4b1 12 if(x < 0 || x > 83)
tim007 0:be75535cf4b1 13 return;
tim007 0:be75535cf4b1 14 if(y < 0 || y > 47)
tim007 0:be75535cf4b1 15 return;
tim007 0:be75535cf4b1 16
tim007 0:be75535cf4b1 17 N5110::setPixel(x,y);
tim007 0:be75535cf4b1 18 }
tim007 0:be75535cf4b1 19 };
tim007 0:be75535cf4b1 20 N5110 lcd (dp13 ,dp24 ,dp23 ,dp25 ,dp2 ,dp6 , dp18);
tim007 0:be75535cf4b1 21
tim007 0:be75535cf4b1 22
tim007 0:be75535cf4b1 23 int X,Y, VIx, VIy;
tim007 0:be75535cf4b1 24
tim007 0:be75535cf4b1 25 int px, py, pvx, pvy;
tim007 0:be75535cf4b1 26 int brojac = 0;
tim007 0:be75535cf4b1 27 DigitalOut enable(dp14);
tim007 0:be75535cf4b1 28
tim007 0:be75535cf4b1 29
tim007 0:be75535cf4b1 30
tim007 0:be75535cf4b1 31
tim007 0:be75535cf4b1 32
tim007 0:be75535cf4b1 33
tim007 0:be75535cf4b1 34 void crtaj()
tim007 0:be75535cf4b1 35 {
tim007 0:be75535cf4b1 36 //clear baklava
tim007 0:be75535cf4b1 37 lcd.clearPixel(px, py);
tim007 0:be75535cf4b1 38 lcd.clearPixel(px+1, py);
tim007 0:be75535cf4b1 39 lcd.clearPixel(px+2, py);
tim007 0:be75535cf4b1 40 lcd.clearPixel(px-1, py);
tim007 0:be75535cf4b1 41 lcd.clearPixel(px-2, py);
tim007 0:be75535cf4b1 42 lcd.clearPixel(px, py+1);
tim007 0:be75535cf4b1 43 lcd.clearPixel(px, py+2);
tim007 0:be75535cf4b1 44 lcd.clearPixel(px, py-1);
tim007 0:be75535cf4b1 45 lcd.clearPixel(px, py-2);
tim007 0:be75535cf4b1 46 lcd.clearPixel(px+1, py+1);
tim007 0:be75535cf4b1 47 lcd.clearPixel(px+1, py-1);
tim007 0:be75535cf4b1 48 lcd.clearPixel(px-1, py-1);
tim007 0:be75535cf4b1 49 lcd.clearPixel(px-1, py+1);
tim007 0:be75535cf4b1 50
tim007 0:be75535cf4b1 51 px = X;
tim007 0:be75535cf4b1 52 py = Y;
tim007 0:be75535cf4b1 53 //crtaj baklava
tim007 0:be75535cf4b1 54 lcd.setPixel(X, Y);
tim007 0:be75535cf4b1 55 lcd.setPixel(X+1, Y);
tim007 0:be75535cf4b1 56 lcd.setPixel(X+2, Y);
tim007 0:be75535cf4b1 57 lcd.setPixel(X-1, Y);
tim007 0:be75535cf4b1 58 lcd.setPixel(X-2, Y);
tim007 0:be75535cf4b1 59 lcd.setPixel(X, Y+1);
tim007 0:be75535cf4b1 60 lcd.setPixel(X, Y+2);
tim007 0:be75535cf4b1 61 lcd.setPixel(X, Y-1);
tim007 0:be75535cf4b1 62 lcd.setPixel(X, Y-2);
tim007 0:be75535cf4b1 63 lcd.setPixel(X+1, Y+1);
tim007 0:be75535cf4b1 64 lcd.setPixel(X+1, Y-1);
tim007 0:be75535cf4b1 65 lcd.setPixel(X-1, Y-1);
tim007 0:be75535cf4b1 66 lcd.setPixel(X-1, Y+1);
tim007 0:be75535cf4b1 67
tim007 0:be75535cf4b1 68 //clear viljuska
tim007 0:be75535cf4b1 69 lcd.clearPixel(pvx-3, pvy-3);
tim007 0:be75535cf4b1 70 lcd.clearPixel(pvx-3, pvy-4);
tim007 0:be75535cf4b1 71 lcd.clearPixel(pvx-3, pvy-5);
tim007 0:be75535cf4b1 72 lcd.clearPixel(pvx-4, pvy-6);
tim007 0:be75535cf4b1 73 lcd.clearPixel(pvx-5, pvy-3);
tim007 0:be75535cf4b1 74 lcd.clearPixel(pvx-5, pvy-4);
tim007 0:be75535cf4b1 75 lcd.clearPixel(pvx-5, pvy-5);
tim007 0:be75535cf4b1 76 lcd.clearPixel(pvx-5, pvy-6);
tim007 0:be75535cf4b1 77 lcd.clearPixel(pvx-5, pvy-7);
tim007 0:be75535cf4b1 78 lcd.clearPixel(pvx-5, pvy-8);
tim007 0:be75535cf4b1 79 lcd.clearPixel(pvx-5, pvy-9);
tim007 0:be75535cf4b1 80 lcd.clearPixel(pvx-5, pvy-10);
tim007 0:be75535cf4b1 81 lcd.clearPixel(pvx-6, pvy-6);
tim007 0:be75535cf4b1 82 lcd.clearPixel(pvx-7, pvy-5);
tim007 0:be75535cf4b1 83 lcd.clearPixel(pvx-7, pvy-4);
tim007 0:be75535cf4b1 84 lcd.clearPixel(pvx-7, pvy-3);
tim007 0:be75535cf4b1 85
tim007 0:be75535cf4b1 86 pvx = VIx;
tim007 0:be75535cf4b1 87 pvy = VIy;
tim007 0:be75535cf4b1 88 //viljuska
tim007 0:be75535cf4b1 89 lcd.setPixel(VIx-3, VIy-3);
tim007 0:be75535cf4b1 90 lcd.setPixel(VIx-3, VIy-4);
tim007 0:be75535cf4b1 91 lcd.setPixel(VIx-3, VIy-5);
tim007 0:be75535cf4b1 92 lcd.setPixel(VIx-4, VIy-6);
tim007 0:be75535cf4b1 93 lcd.setPixel(VIx-5, VIy-3);
tim007 0:be75535cf4b1 94 lcd.setPixel(VIx-5, VIy-4);
tim007 0:be75535cf4b1 95 lcd.setPixel(VIx-5, VIy-5);
tim007 0:be75535cf4b1 96 lcd.setPixel(VIx-5, VIy-6);
tim007 0:be75535cf4b1 97 lcd.setPixel(VIx-5, VIy-7);
tim007 0:be75535cf4b1 98 lcd.setPixel(VIx-5, VIy-8);
tim007 0:be75535cf4b1 99 lcd.setPixel(VIx-5, VIy-9);
tim007 0:be75535cf4b1 100 lcd.setPixel(VIx-5, VIy-10);
tim007 0:be75535cf4b1 101 lcd.setPixel(VIx-6, VIy-6);
tim007 0:be75535cf4b1 102 lcd.setPixel(VIx-7, VIy-5);
tim007 0:be75535cf4b1 103 lcd.setPixel(VIx-7, VIy-4);
tim007 0:be75535cf4b1 104 lcd.setPixel(VIx-7, VIy-3);
tim007 0:be75535cf4b1 105
tim007 0:be75535cf4b1 106 lcd.refresh();
tim007 0:be75535cf4b1 107 }
tim007 0:be75535cf4b1 108
tim007 0:be75535cf4b1 109 void update(){
tim007 0:be75535cf4b1 110
tim007 0:be75535cf4b1 111 if (VRx<1.0/3.0){
tim007 0:be75535cf4b1 112 if(X >= 9)X--;
tim007 0:be75535cf4b1 113 }
tim007 0:be75535cf4b1 114 else if (VRx > 2.0/3.0){
tim007 0:be75535cf4b1 115 if( X <= 78)X++;
tim007 0:be75535cf4b1 116 }
tim007 0:be75535cf4b1 117
tim007 0:be75535cf4b1 118 if (VRy<1.0/3.0){
tim007 0:be75535cf4b1 119 if(Y >= 12)Y--;
tim007 0:be75535cf4b1 120 }
tim007 0:be75535cf4b1 121 else if (VRy > 2.0/3.0){
tim007 0:be75535cf4b1 122 if( Y <= 42)Y++;
tim007 0:be75535cf4b1 123 }
tim007 0:be75535cf4b1 124
tim007 0:be75535cf4b1 125
tim007 0:be75535cf4b1 126 }
tim007 0:be75535cf4b1 127
tim007 0:be75535cf4b1 128 void updateViljuska()
tim007 0:be75535cf4b1 129 {
tim007 0:be75535cf4b1 130 VIx = (VIx - X)*2/3 + X;
tim007 0:be75535cf4b1 131 VIy = (VIy - Y)*2/3 + Y;
tim007 0:be75535cf4b1 132 /*
tim007 0:be75535cf4b1 133 if(X > VIx) VIx++;
tim007 0:be75535cf4b1 134 else if( X < VIx) VIx--;
tim007 0:be75535cf4b1 135
tim007 0:be75535cf4b1 136 if(Y > VIy) VIy++;
tim007 0:be75535cf4b1 137 else if(Y < VIy) VIy--; */
tim007 0:be75535cf4b1 138 }
tim007 0:be75535cf4b1 139
tim007 0:be75535cf4b1 140 int main()
tim007 0:be75535cf4b1 141 {
tim007 0:be75535cf4b1 142 enable = 1;
tim007 0:be75535cf4b1 143
tim007 0:be75535cf4b1 144 lcd.init();
tim007 0:be75535cf4b1 145
tim007 0:be75535cf4b1 146 lcd.clear();
tim007 0:be75535cf4b1 147 Timer timer, t2;
tim007 0:be75535cf4b1 148 timer.start();
tim007 0:be75535cf4b1 149 t2.start();
tim007 0:be75535cf4b1 150 VIx = VIy = X = Y = 24;
tim007 0:be75535cf4b1 151
tim007 0:be75535cf4b1 152 while(1) {
tim007 0:be75535cf4b1 153 if(timer.read_ms() > 100)
tim007 0:be75535cf4b1 154 {
tim007 0:be75535cf4b1 155 update();
tim007 0:be75535cf4b1 156 timer.reset();
tim007 0:be75535cf4b1 157 timer.start();
tim007 0:be75535cf4b1 158 }
tim007 0:be75535cf4b1 159 if(t2.read_ms() > 500)
tim007 0:be75535cf4b1 160 {
tim007 0:be75535cf4b1 161 updateViljuska();
tim007 0:be75535cf4b1 162 t2.reset();
tim007 0:be75535cf4b1 163 t2.start();
tim007 0:be75535cf4b1 164 }
tim007 0:be75535cf4b1 165 lcd.setXYAddress(0,0);
tim007 0:be75535cf4b1 166 crtaj();
tim007 0:be75535cf4b1 167 }
tim007 0:be75535cf4b1 168 }