Basic example showing how to use the Compass (LSM303 device with Accelerometer and Magnetometer) present on DISCO_L476VG board.
Dependencies: BSP_DISCO_L476VG COMPASS_DISCO_L476VG
Diff: main.cpp
- Revision:
- 0:211cb2effe6e
- Child:
- 4:875e95338f6d
diff -r 000000000000 -r 211cb2effe6e main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Sep 22 14:53:48 2015 +0000 @@ -0,0 +1,32 @@ +#include "mbed.h" +#include "COMPASS_DISCO_L476VG.h" + +COMPASS_DISCO_L476VG compass; + +DigitalOut led1(LED1); + +int main() +{ + int16_t MagBuffer[3]; + int16_t AccBuffer[3]; + + printf("Compass started\n"); + + while(1) { + + // Read acceleremoter and magnetometer values + compass.AccGetXYZ(AccBuffer); + compass.MagGetXYZ(MagBuffer); + // Display values + printf("Acc X = %d\n", AccBuffer[0]); + printf("Acc Y = %d\n", AccBuffer[1]); + printf("Acc Z = %d\n", AccBuffer[2]); + printf("Mag X = %d\n", MagBuffer[0]); + printf("Mag Y = %d\n", MagBuffer[1]); + printf("Mag Z = %d\n", MagBuffer[2]); + printf("\033[6A"); // Moves cursor up x lines (x value is between [ and A) + + led1 = !led1; + wait(1); + } +}