![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First
Revision 6:459d1eb2cc23, committed 2016-01-14
- Comitter:
- asloop18
- Date:
- Thu Jan 14 22:52:20 2016 +0000
- Parent:
- 5:98ad3701ec24
- Commit message:
- working game; mission accomplished
Changed in this revision
diff -r 98ad3701ec24 -r 459d1eb2cc23 LCD1.cpp --- a/LCD1.cpp Thu Jan 14 22:03:54 2016 +0000 +++ b/LCD1.cpp Thu Jan 14 22:52:20 2016 +0000 @@ -7,13 +7,12 @@ #include "Arial24x23.h" #include "pavement_48x34.h" -Serial pc(USBTX, USBRX); +//Serial pc(USBTX, USBRX); 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=3; -int x,y; int pos1=160; int pos2=120; @@ -24,12 +23,16 @@ { myLCD.set_orientation(orient); myLCD.background(Black); - myLCD.cls(); + myLCD.cls(); } void LCD1(int x,int y) { - myLCD.cls(); - myLCD.circle(160,120,12,White); - myLCD.fillcircle(x,y,6,Red); + myLCD.fillcircle(x,y,6,Black); +} + +void LCD2(int x,int y) +{ + myLCD.fillcircle(x,y,6,Red); + myLCD.circle(160,120,12,White); } \ No newline at end of file
diff -r 98ad3701ec24 -r 459d1eb2cc23 LCD1.h --- a/LCD1.h Thu Jan 14 22:03:54 2016 +0000 +++ b/LCD1.h Thu Jan 14 22:52:20 2016 +0000 @@ -4,5 +4,6 @@ void LCD1(int x, int y); void LCD_init(); +void LCD2(int x, int y); #endif
diff -r 98ad3701ec24 -r 459d1eb2cc23 acc.cpp --- a/acc.cpp Thu Jan 14 22:03:54 2016 +0000 +++ b/acc.cpp Thu Jan 14 22:52:20 2016 +0000 @@ -9,8 +9,7 @@ Serial pc(USBTX, USBRX); char buffer[6]; //raw filler data int16_t data[3]; //16bit twos-compliment integer data -float x,y,z; //set up floats for values to display - + void acc_init(void){ cs=1; //initially off acc.format(8,3); //8bit, mode 3 @@ -26,6 +25,7 @@ } float acc_sense(char axis){ + float x,y; cs=0; acc.write(0x80|0x40|0x32); //RW bit high, MB bit high, address to ask for a reading for (int i=0;i<=5;i++){buffer[i]=acc.write(0x00);} //read 6bytes @@ -34,8 +34,10 @@ data[1]=buffer[3]<<8|buffer[2]; //y combine MSB and LSB data[2]=buffer[5]<<8|buffer[4]; //z - x=atan(data[0],data[2]); - y=atan(data[1],data[2]); + x=(atan2((double)data[0],(double)data[2])*180/3.1416); //convert the signal into an angle, to be passed out as x,y + y=(atan2((double)data[1],(double)data[2])*180/3.1416); + +// pc.printf("Angle x = %1.2f \t Angle y = %1.2f \n\r", x,y); if(axis==1) return x; //if asked for x, give x if(axis==2) return y; //if asked for y, give y
diff -r 98ad3701ec24 -r 459d1eb2cc23 acc.h --- a/acc.h Thu Jan 14 22:03:54 2016 +0000 +++ b/acc.h Thu Jan 14 22:52:20 2016 +0000 @@ -6,4 +6,6 @@ #include "mbed.h" void acc_init(void); -float acc_sense(char axis); \ No newline at end of file +float acc_sense(char axis); + +#endif \ No newline at end of file
diff -r 98ad3701ec24 -r 459d1eb2cc23 main.cpp --- a/main.cpp Thu Jan 14 22:03:54 2016 +0000 +++ b/main.cpp Thu Jan 14 22:52:20 2016 +0000 @@ -1,24 +1,31 @@ #include "mbed.h" #include "LCD1.h" +#include "acc.h" -int x,y; +float x,y; +float dx,dy; //degrees x,y -int main() { +int main() +{ + acc_init(); LCD_init(); - acc_init(); - while(1){ - - + x =160; + y =120; + dx =0; + dy=0; + while(1) + { + dx = acc_sense(1); + dy = acc_sense(2); + LCD1(x,y); //send pos to LCD to display + x=x+dy/5; //apply x of sensor to y of screen (alignment) + y=y+dx/5; //vice-versa - ifx>< - ify<> - LED1(x,y); - - - - LCD_init(); - while(1) - { - LCD1(160,120); + if(x>314)x=314; //prevent loss of bubble + if(x<6)x=6; + if(y>234)y=234; + if(y<6)y=6; + + LCD2(x,y); //send pos to LCD to display } }