
MMA8451
Dependencies: MMA8451Q
Revision 3:ad69174423e0, committed 2018-11-19
- Comitter:
- jiuk
- Date:
- Mon Nov 19 02:05:05 2018 +0000
- Parent:
- 2:5fb1ae9832d3
- Commit message:
- acelerometro version chip mma8451
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Feb 15 18:11:08 2018 +0000 +++ b/main.cpp Mon Nov 19 02:05:05 2018 +0000 @@ -2,17 +2,16 @@ #include "rtos.h" #include "MMA8451Q.h" - PinName const SDA = PTE25; - PinName const SCL = PTE24; + PinName const SDA = PC_9; + PinName const SCL = PB_8; + //SDA PC_9 + //SCL PB_8 -#define MMA8451_I2C_ADDRESS (0x1d<<1) +#define MMA8451_I2C_ADDRESS (0x68) int main(void) { MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); - PwmOut rled(LED1); - PwmOut gled(LED2); - PwmOut bled(LED3); Serial pc(USBTX, USBRX); // tx, rx float threshold = .50; float min_threshold = 0.25; @@ -26,62 +25,41 @@ x = acc.getAccX(); y = acc.getAccY(); z = acc.getAccZ(); - + pc.printf("acelerometro: %d\n", x); + pc.printf("acelerometro: %d\n", y); + pc.printf("acelerometro: %d\n", z); //flat if(z>threshold && abs(x)< min_threshold && abs(y)< min_threshold) { - rled = 1.0f - abs(x); - gled = 1.0f - abs(y); - bled = 1.0f - abs(z); pc.printf("FLAT\n\r"); pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n\r", x, y, z); }else if(y<-threshold && abs(z)<min_threshold && abs(x)<min_threshold) { - rled = 1.0f - abs(x); - gled = 1.0f - abs(y); - bled = 1.0f - abs(z); pc.printf("RIGHT\n\r"); pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n\r", x, y, z); }else if(y>threshold && abs(z)<min_threshold && abs(x)<min_threshold) { - rled = 1.0f - abs(x); - gled = 1.0f - abs(y); - bled = 1.0f - abs(z); pc.printf("LEFT\n\r"); pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n\r", x, y, z); }else if(x< -threshold && abs(z)<min_threshold && abs(y)<min_threshold) { - rled = 1.0f - abs(x); - gled = 1.0f - abs(y); - bled = 1.0f - abs(z); pc.printf("DOWN\n\r"); pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n\r", x, y, z); }else if(x> threshold && abs(z)<min_threshold && abs(y)<min_threshold) { - rled = 1.0f - abs(x); - gled = 1.0f - abs(y); - bled = 1.0f - abs(z); pc.printf("UP\n\r"); pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n\r", x, y, z); }else if(z<-threshold && abs(y)<min_threshold && abs(x)<min_threshold) { - rled = 1.0f - abs(x); - gled = 1.0f - abs(y); - bled = 1.0f - abs(z); pc.printf("OVER\n\r"); pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n\r", x, y, z); } - else{ - rled = 1; - gled= 1; - bled =1; - } Thread::wait(300); }