![](/media/cache/profiles/IvyS.JPG.50x50_q85.jpg)
state led / position change
Fork of Accelerometer_example by
main.cpp
- Committer:
- Ivone
- Date:
- 2018-02-15
- Revision:
- 2:18e28291bc02
- Parent:
- 0:a1caba5c4e48
- Child:
- 3:ca2e99f6b193
File content as of revision 2:18e28291bc02:
#include "mbed.h" #include "rtos.h" #include "MMA8451Q.h" PinName const SDA = PTE25; PinName const SCL = PTE24; #define MMA8451_I2C_ADDRESS (0x1d<<1) 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 pc.printf("MMA8451 ID: %d\n", acc.getWhoAmI()); while (true) { float x, y, z; x = acc.getAccX(); y = acc.getAccY(); z = acc.getAccZ(); rled = 1.0f - abs(x); gled = 1.0f - abs(y); bled = 1.0f - abs(z); Thread::wait(300); pc.printf("X:flat ,Y:right ,Z:left\n", x,y,z); // if (x> 0){ // pc.printf("X:flat ,Y:right ,Z:left\n", x,y,z); //} //pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n", x, y, z); } }