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:
0:db5358403ca6
Child:
1:96861dcaec35
diff -r 000000000000 -r db5358403ca6 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 31 17:39:18 2018 +0000
@@ -0,0 +1,48 @@
+#include "mbed.h"
+
+    Serial          pc          (PA_2, PA_3, 921600);
+
+    DigitalOut      led1        (PA_5);
+    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);
+}
+
+
+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);
+        led1 = !led1;
+        led2 = !led2;
+        wait (0.2);
+    }
+}