Using an accelerometer to move a ball on an LED screen.

Dependencies:   UniGraphic mbed

Committer:
bentogami
Date:
Wed Jan 20 22:00:15 2016 +0000
Revision:
2:c6bf8599c398
Parent:
1:c436c1b8333b
Mission complete (for real)!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bentogami 0:708949ec9140 1 #include "mbed.h"
bentogami 0:708949ec9140 2 #include "ADXL.h"
bentogami 0:708949ec9140 3 #include "Arial12x12.h"
bentogami 0:708949ec9140 4 #include "Arial24x23.h"
bentogami 0:708949ec9140 5 #include "ILI932x.h"
bentogami 0:708949ec9140 6
bentogami 0:708949ec9140 7 Serial pc(USBTX, USBRX);
bentogami 0:708949ec9140 8 float data[6];
bentogami 0:708949ec9140 9 PinName dataBus[]= {p30, p29, p28, p27, p26, p25, p24, p23};
bentogami 0:708949ec9140 10 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
bentogami 0:708949ec9140 11 char orient=4;
bentogami 2:c6bf8599c398 12 int X = 120, Y = 160, oldY, oldX;
bentogami 0:708949ec9140 13
bentogami 0:708949ec9140 14 int main() {
bentogami 0:708949ec9140 15 accConfig();
bentogami 0:708949ec9140 16 myLCD.set_orientation(orient);
bentogami 0:708949ec9140 17 //t.start();
bentogami 0:708949ec9140 18 myLCD.set_font((unsigned char*) Arial12x12);
bentogami 0:708949ec9140 19 myLCD.background(Black); // set background to red
bentogami 0:708949ec9140 20 myLCD.foreground(White); // set chars to black
bentogami 0:708949ec9140 21 myLCD.cls(); // clear the screen
bentogami 1:c436c1b8333b 22 /*
bentogami 0:708949ec9140 23 myLCD.locate((myLCD.width()-7)/2,myLCD.height()/2); // from our view, first is yPos, second is xPos
bentogami 0:708949ec9140 24 myLCD.printf("Target Practice\r\n");
bentogami 0:708949ec9140 25 wait(2);
bentogami 0:708949ec9140 26 myLCD.cls();
bentogami 1:c436c1b8333b 27 */
bentogami 1:c436c1b8333b 28 wait(1);
bentogami 2:c6bf8599c398 29 myLCD.circle(120,160,12,White);
bentogami 0:708949ec9140 30 while(1) {
bentogami 0:708949ec9140 31 //temporary code:
bentogami 2:c6bf8599c398 32 myLCD.fillcircle(oldX,oldY,6,Black);
bentogami 2:c6bf8599c398 33 myLCD.fillcircle(X,Y,6,Blue);
bentogami 2:c6bf8599c398 34 oldX = X;
bentogami 2:c6bf8599c398 35 oldY = Y;
bentogami 0:708949ec9140 36 getAccel(data);
bentogami 1:c436c1b8333b 37 pc.printf("x = %1.2fg\t y = %1.2fg\t z = %1.2fg \n\r", data[0], data[1], data[2]); //print
bentogami 1:c436c1b8333b 38 if (((X + data[0]) < myLCD.width()-10) && (X + data[0]) > 10)
bentogami 1:c436c1b8333b 39 X += data[0]*30;
bentogami 1:c436c1b8333b 40 if ((Y + data[1]) < myLCD.height()-10 && (Y + data[1]) > 10)
bentogami 1:c436c1b8333b 41 Y -= data[1]*30;
bentogami 2:c6bf8599c398 42 wait(0.002);
bentogami 1:c436c1b8333b 43
bentogami 0:708949ec9140 44 //insert correct code here:
bentogami 0:708949ec9140 45
bentogami 0:708949ec9140 46 }
bentogami 0:708949ec9140 47 }