Daniel Vilela
/
MMA8451Q
Use case
main.cpp@0:5894195daf1d, 2019-10-16 (annotated)
- Committer:
- daniwestside
- Date:
- Wed Oct 16 22:33:20 2019 +0000
- Revision:
- 0:5894195daf1d
MMA8451Q use case
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
daniwestside | 0:5894195daf1d | 1 | #include "mbed.h" |
daniwestside | 0:5894195daf1d | 2 | #include "MMA8451Q.h" |
daniwestside | 0:5894195daf1d | 3 | |
daniwestside | 0:5894195daf1d | 4 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
daniwestside | 0:5894195daf1d | 5 | |
daniwestside | 0:5894195daf1d | 6 | Serial pc(USBTX, USBRX, 9600); |
daniwestside | 0:5894195daf1d | 7 | |
daniwestside | 0:5894195daf1d | 8 | int main(void) { |
daniwestside | 0:5894195daf1d | 9 | MMA8451Q acc(PA_10, PA_9, MMA8451_I2C_ADDRESS); |
daniwestside | 0:5894195daf1d | 10 | float x, y, z; |
daniwestside | 0:5894195daf1d | 11 | while (true) { |
daniwestside | 0:5894195daf1d | 12 | x = acc.getAccX(); |
daniwestside | 0:5894195daf1d | 13 | y = acc.getAccY(); |
daniwestside | 0:5894195daf1d | 14 | z = acc.getAccZ(); |
daniwestside | 0:5894195daf1d | 15 | pc.printf("x = %f\t y = %f\t z = %f\n\r", x, y, z); |
daniwestside | 0:5894195daf1d | 16 | |
daniwestside | 0:5894195daf1d | 17 | wait(5); |
daniwestside | 0:5894195daf1d | 18 | } |
daniwestside | 0:5894195daf1d | 19 | } |