ST / Mbed OS DISCO_L476VG_Compass

Dependencies:   BSP_DISCO_L476VG COMPASS_DISCO_L476VG

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "COMPASS_DISCO_L476VG.h"
00003 
00004 COMPASS_DISCO_L476VG compass;
00005 
00006 DigitalOut led1(LED1);
00007 
00008 int main()
00009 {
00010     int16_t MagBuffer[3];
00011     int16_t AccBuffer[3];
00012   
00013     printf("Compass started (LD5 should blink)\n");
00014   
00015     while(1) {
00016       
00017         // Read acceleremoter and magnetometer values
00018         compass.AccGetXYZ(AccBuffer);
00019         compass.MagGetXYZ(MagBuffer);
00020         // Display values      
00021         printf("Acc X = %d\n", AccBuffer[0]);
00022         printf("Acc Y = %d\n", AccBuffer[1]);
00023         printf("Acc Z = %d\n", AccBuffer[2]);
00024         printf("Mag X = %d\n", MagBuffer[0]);
00025         printf("Mag Y = %d\n", MagBuffer[1]);
00026         printf("Mag Z = %d\n", MagBuffer[2]);
00027         printf("\033[6A"); // Moves cursor up x lines (x value is between [ and A)
00028       
00029         led1 = !led1;
00030         ThisThread::sleep_for(1000);
00031     }
00032 }