CMPS03 Compass HelloWorld Program
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.
main.cpp
- Committer:
- haarkon
- Date:
- 2018-05-31
- Revision:
- 0:db5358403ca6
- Child:
- 1:96861dcaec35
File content as of revision 0:db5358403ca6:
#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); } }