David Wynn
/
mbed_max2719
ECE Project
Diff: main.cpp
- Revision:
- 2:577acf73d01f
- Parent:
- 1:37f364164ca9
- Child:
- 3:ee4b3ea36ec7
diff -r 37f364164ca9 -r 577acf73d01f main.cpp --- a/main.cpp Sun Apr 10 19:19:15 2016 +0000 +++ b/main.cpp Sun Apr 10 19:41:30 2016 +0000 @@ -17,7 +17,7 @@ #define MMA8451_I2C_ADDRESS (0x1d<<1) const unsigned char led1[]= { - 0xFF,0x18,0x18,0x18,0x18,0x18,0x18,0xFF + 0xFF,0xB4,0x15,0xD1,0x85,0xB5,0x95,0xFF }; //H const unsigned char led2[]= { 0x1F,0x60,0x80,0x40,0x40,0x80,0x60,0x1F @@ -76,26 +76,43 @@ Init_MAX7219(); // Initialize the LED controller MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); + unsigned char position[] = { + 0x03, 0x80 + }; + for(int i=1; i<9; i++) // Write first character (8 rows) + SPI_Write2(i,led1[i-1]); while (1) { - + float x, y, z; x = acc.getAccX(); y = acc.getAccY(); z = acc.getAccZ(); + if(x > 0.5){ + printf("Left \n"); + position[1] = position[1]*2; + }else if(x < -0.5){ + printf("Right \n"); + position[1] = position[1]/2; + }else if(y > 0.5){ + printf("Up \n"); + position[0] = position[1]-1; + }else if(y < -0.5){ + printf("Down \n"); + position[0] = position[1]+2; + } /* rled = 1.0f - abs(x); gled = 1.0f - abs(y); bled = 1.0f - abs(z); - direction(x,y);*/ + */ + direction(x,y); //wait(0.5f); - for(int i=1; i<9; i++) // Write first character (8 rows) - SPI_Write2(i,led1[i-1]); + + wait(1); // 1 sec delay - for(int i=1; i<9; i++) // Write second character - SPI_Write2(i,led2[i-1]); - wait(1); // 1 sec delay + SPI_Write2(position[0], position[1]); }