CMPS03 Compass HelloWorld Program

Dependencies:   mbed CMPS03

This program is an example of how to use the CMPS03 compass library.

People may also use the CMPS03 I2C library that can be found in Mbed component section.

Revision:
1:96861dcaec35
Parent:
0:db5358403ca6
Child:
2:4dae0a194d00
diff -r db5358403ca6 -r 96861dcaec35 main.cpp
--- a/main.cpp	Thu May 31 17:39:18 2018 +0000
+++ b/main.cpp	Fri Jun 01 06:57:41 2018 +0000
@@ -1,4 +1,5 @@
 #include "mbed.h"
+#include "CMPS03.h"
 
     Serial          pc          (PA_2, PA_3, 921600);
 
@@ -6,41 +7,18 @@
     DigitalOut      led2        (PD_2);
     DigitalOut      disquette   (PA_12);
 
-    InterruptIn     boussole   (PC_4);
-    Timer           _tim;
-
-    long    _startTime, _stopTime;
-    double  _pwmBearing;
-
-void bRise(void)
-{
-    _startTime = _tim.read_us();
-}
-
-void bFall(void)
-{
-
-    _stopTime = _tim.read_us();
-    _pwmBearing = ((double)((long)(_stopTime - _startTime) - 1000)/100.0);
-}
-
+    CMPS03          boussole    (PC_4);
 
 int main()
 {
 
-    boussole.rise(&bRise);
-    boussole.fall(&bFall);
-    boussole.enable_irq();
-    _tim.reset();
-    _tim.start();
-
     pc.printf ("\nHelloWorld\n\r");
     led1 = 1;
     led2 = 0;
     disquette = 0;
     
     while(1) {
-        pc.printf("\r%5.2lf\t %8X\t %8X",_pwmBearing, _startTime, _stopTime);
+        pc.printf("\r%5.2lf", boussole.getBearing());
         led1 = !led1;
         led2 = !led2;
         wait (0.2);