![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Using an accelerometer to move a ball on an LED screen.
Diff: main.cpp
- Revision:
- 0:708949ec9140
- Child:
- 1:c436c1b8333b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jan 14 23:22:30 2016 +0000 @@ -0,0 +1,41 @@ +#include "mbed.h" +#include "ADXL.h" +#include "Arial12x12.h" +#include "Arial24x23.h" +#include "ILI932x.h" + +Serial pc(USBTX, USBRX); +float data[6]; +PinName dataBus[]= {p30, p29, p28, p27, p26, p25, p24, p23}; +ILI932x myLCD(BUS_8, dataBus, p15, p17, p16, p14, p20, "myLCD", 240, 320); // Bus 8 bit, bus pin array, CS, RST, DC, WR, RD, name, xpixels, ypixels +char orient=4; +int X = 120, Y = 160; + +int main() { + accConfig(); + myLCD.set_orientation(orient); + //t.start(); + myLCD.set_font((unsigned char*) Arial12x12); + myLCD.background(Black); // set background to red + myLCD.foreground(White); // set chars to black + myLCD.cls(); // clear the screen + myLCD.locate((myLCD.width()-7)/2,myLCD.height()/2); // from our view, first is yPos, second is xPos + myLCD.printf("Target Practice\r\n"); + wait(2); + myLCD.cls(); + while(1) { + //temporary code: + myLCD.circle(120,160,12,White); + myLCD.fillcircle(X,Y,6,Green); + getAccel(data); + pc.printf("x = %+1.2fg\t y = %+1.2fg\n\r", data[0], data[1]); //print + if (X < myLCD.width() && X > 0) + X += data[0]/0.004; + if (Y < myLCD.height() && Y > 0) + Y += data[1]/0.004; + wait(0.02); + myLCD.cls(); + //insert correct code here: + + } +}