LSM303DLH Test Program for get angle.
Dependencies: L3GD20 LSM303DLHC SDFileSystemLatch mbed nrf51_rtc
Fork of LSM303DLHTest by
main.cpp@4:3c677edffb13, 2012-05-06 (annotated)
- Committer:
- tosihisa
- Date:
- Sun May 06 05:30:44 2012 +0000
- Revision:
- 4:3c677edffb13
- Parent:
- 3:f3796683b4c9
- Child:
- 5:b1a689c55f59
cut space.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tosihisa | 0:750784997b84 | 1 | |
tosihisa | 0:750784997b84 | 2 | #include "mbed.h" |
tosihisa | 4:3c677edffb13 | 3 | #include "LSM303DLH.h" |
tosihisa | 0:750784997b84 | 4 | |
tosihisa | 4:3c677edffb13 | 5 | Serial debug(USBTX,USBRX); |
tosihisa | 4:3c677edffb13 | 6 | LSM303DLH compass(p28, p27); |
tosihisa | 0:750784997b84 | 7 | |
tosihisa | 4:3c677edffb13 | 8 | int main() { |
tosihisa | 4:3c677edffb13 | 9 | float hdg; |
tosihisa | 4:3c677edffb13 | 10 | float hdgV; |
tosihisa | 4:3c677edffb13 | 11 | vector acc; |
tosihisa | 4:3c677edffb13 | 12 | vector mag; |
tosihisa | 4:3c677edffb13 | 13 | debug.format(8,Serial::None,1); |
tosihisa | 4:3c677edffb13 | 14 | debug.baud(115200); |
tosihisa | 4:3c677edffb13 | 15 | debug.printf("LSM303DLH Test\x0d\x0a"); |
tosihisa | 4:3c677edffb13 | 16 | compass.setOffset(0.00,0.00,0.00); // example calibration |
tosihisa | 4:3c677edffb13 | 17 | compass.setScale(1.00,1.00,1.00); // example calibration |
tosihisa | 4:3c677edffb13 | 18 | while(1) { |
tosihisa | 4:3c677edffb13 | 19 | compass.read(acc,mag); |
tosihisa | 4:3c677edffb13 | 20 | hdg = compass.heading(); |
tosihisa | 4:3c677edffb13 | 21 | hdgV = atan2(acc.y,acc.z) * 180/M_PI; |
tosihisa | 4:3c677edffb13 | 22 | debug.printf("ACC: %6.2f %6.2f %6.2f Heading: %6.2f %6.2f\n",acc.x,acc.y,acc.z,hdgV,hdg); |
tosihisa | 4:3c677edffb13 | 23 | wait(0.1); |
tosihisa | 4:3c677edffb13 | 24 | } |
tosihisa | 4:3c677edffb13 | 25 | } |
tosihisa | 3:f3796683b4c9 | 26 |