fsfs
Dependencies: 4DGL-uLCD-SE LSM303D mbed
Fork of LSM303D_SPI by
Diff: main.cpp
- Revision:
- 1:bad5121a35c7
- Parent:
- 0:684294feee71
- Child:
- 2:2a81657780dc
--- a/main.cpp Tue Oct 21 16:49:53 2014 +0000 +++ b/main.cpp Thu Jan 15 19:55:22 2015 +0000 @@ -1,153 +1,52 @@ #include "mbed.h" #include "LSM303D.h" +#include <string> SPI spi(p5, p6, p7); // mosi, miso, sclk +SPI spi2(p11, p12, p13); + +Serial pc(USBTX, USBRX); // tx, rx LSM303D sensor1(spi,p15); LSM303D sensor2(spi,p16); LSM303D sensor3(spi,p17); LSM303D sensor4(spi,p18); -#include "uLCD_4DGL.h" - -uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; +LSM303D sensor5(spi2,p27); +LSM303D sensor6(spi2,p28); +LSM303D sensor7(spi2,p29); +LSM303D sensor8(spi2,p30); int main() { - // Chip must be deselected sensor1.initialize(); - float vx_old = sensor1.magnitometer(2); + sensor2.initialize(); + sensor3.initialize(); + sensor4.initialize(); - float fx=63.0,fy=2.0,vx= 0.0,vy=0.4; - int x=63,y=2,radius=2; - uLCD.background_color(BLACK); - uLCD.cls(); + sensor5.initialize(); + sensor6.initialize(); + sensor7.initialize(); + sensor8.initialize(); + - int pts[20]; - for (int level=1; level<=5; level++) - { - if (level == 1) - { - pts[0] = 30; pts[1] = 63; - pts[2] = 96; pts[3] = 63; - } - else if (level == 2) - { - pts[0] = 0; pts[1] = 40; - pts[2] = 50; pts[3] = 40; - - pts[4] = 76; pts[5] = 80; - pts[6] = 126; pts[7] = 80; - - } - else if (level == 3) - { - pts[0] = 0; pts[1] = 30; - pts[2] = 50; pts[3] = 30; - - pts[4] = 76; pts[5] = 60; - pts[6] = 126; pts[7] = 60; - - pts[8] = 76; pts[9] = 90; - pts[10] = 126; pts[11] = 90; - - } - else if (level == 4) - { - pts[0] = 0; pts[1] = 28; - pts[2] = 50; pts[3] = 28; - - pts[4] = 76; pts[5] = 56; - pts[6] = 126; pts[7] = 56; - - pts[8] = 76; pts[9] = 84; - pts[10] = 126; pts[11] = 84; - - pts[12] = 76; pts[13] = 112; - pts[14] = 126; pts[15] = 112; - } - else - { - pts[0] = 0; pts[1] = 20; - pts[2] = 50; pts[3] = 20; - - pts[4] = 76; pts[5] = 40; - pts[6] = 126; pts[7] = 40; - - pts[8] = 76; pts[9] = 60; - pts[10] = 126; pts[11] = 60; - - pts[12] = 76; pts[13] = 80; - pts[14] = 126; pts[15] = 80; - - pts[16] = 76; pts[17] = 100; - pts[18] = 126; pts[19] = 100; - } + while (true) + { + char c = pc.getc(); + - uLCD.cls(); - for (int i=0; i<level; i++) - { - uLCD.line(pts[4*i], pts[4*i+1], pts[4*i+2], pts[4*i+3], WHITE); - } - - y = 2; - fy = 2; - - while (y<126) - { - vx = (sensor1.magnitometer(2)-vx_old)/100; - //draw ball - uLCD.filled_circle(x, y, radius, RED); - //bounce off edge walls and slow down a bit? - - for (int i=0; i<level; i++) - { - if (x>pts[4*i] && x<pts[4*i+2] && y>pts[4*i+1]-1 && y<pts[4*i+3]+1) - { - uLCD.cls(); - uLCD.text_width(4); //4X size text - uLCD.text_height(4); - uLCD.color(RED); - uLCD.locate(0,0); - uLCD.printf("GAME OVER"); - return 0; - } - } - - uLCD.filled_circle(x, y, radius, BLACK); - //move ball - fx=fx+vx; - fy=fy+vy; - x=(int)fx; - y=(int)fy; - if (x<0) - { - x += 126; - fx = x; - } - if (x>126) - { - x -= 126; - fx = x; - } - - } - uLCD.cls(); - uLCD.text_width(4); //4X size text - uLCD.text_height(4); - uLCD.color(RED); - uLCD.locate(1,1); - - if (level <= 4) - uLCD.printf("%2D",level+1); - else - { - uLCD.locate(1,1); - uLCD.printf("YOU WIN"); - } - wait(1); - - } - + int a[] = {sensor1.magnitometer(0), sensor1.magnitometer(1), sensor1.magnitometer(2), + sensor2.magnitometer(0), sensor2.magnitometer(1), sensor2.magnitometer(2), + sensor3.magnitometer(0), sensor3.magnitometer(1), sensor3.magnitometer(2), + sensor4.magnitometer(0), sensor4.magnitometer(1), sensor4.magnitometer(2), + sensor5.magnitometer(0), sensor5.magnitometer(1), sensor5.magnitometer(2), + sensor6.magnitometer(0), sensor6.magnitometer(1), sensor6.magnitometer(2), + sensor7.magnitometer(0), sensor7.magnitometer(1), sensor7.magnitometer(2), + sensor8.magnitometer(0), sensor8.magnitometer(1), sensor8.magnitometer(2)}; + + int t = a[c-'a']; + pc.printf("%d",t); + + } } \ No newline at end of file