Haozun Sun
/
Accelerometer2_hzsun
I got the structure of the code but did not get every details right
main.cpp
- Committer:
- WilliamMarshQMUL
- Date:
- 2020-02-19
- Revision:
- 4:72b8fb7423dd
- Parent:
- 3:d5c746840139
- Child:
- 6:d58d982c647a
File content as of revision 4:72b8fb7423dd:
#include "mbed.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); ThisThread::sleep_for(300); // wait(0.3); pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n", x, y, z); } }