![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
LSM303DLH Test Program for get angle.
Dependencies: L3GD20 LSM303DLHC SDFileSystemLatch mbed nrf51_rtc
Fork of LSM303DLHTest by
main.cpp@3:f3796683b4c9, 2012-05-06 (annotated)
- Committer:
- tosihisa
- Date:
- Sun May 06 05:14:30 2012 +0000
- Revision:
- 3:f3796683b4c9
- Parent:
- 2:39cdefe3c9f2
- Child:
- 4:3c677edffb13
An angle of inclination is obtained using an accelerometer.
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 | 3:f3796683b4c9 | 3 | #include "LSM303DLH.h" |
tosihisa | 0:750784997b84 | 4 | |
tosihisa | 3:f3796683b4c9 | 5 | Serial debug(USBTX,USBRX); |
tosihisa | 3:f3796683b4c9 | 6 | LSM303DLH compass(p28, p27); |
tosihisa | 0:750784997b84 | 7 | |
tosihisa | 3:f3796683b4c9 | 8 | int main() { |
tosihisa | 3:f3796683b4c9 | 9 | float hdg; |
tosihisa | 3:f3796683b4c9 | 10 | float hdgV; |
tosihisa | 3:f3796683b4c9 | 11 | vector acc; |
tosihisa | 3:f3796683b4c9 | 12 | vector mag; |
tosihisa | 3:f3796683b4c9 | 13 | debug.format(8,Serial::None,1); |
tosihisa | 3:f3796683b4c9 | 14 | debug.baud(115200); |
tosihisa | 3:f3796683b4c9 | 15 | debug.printf("LSM303DLH Test\x0d\x0a"); |
tosihisa | 3:f3796683b4c9 | 16 | compass.setOffset(0.00,0.00,0.00); // example calibration |
tosihisa | 3:f3796683b4c9 | 17 | compass.setScale(1.00,1.00,1.00); // example calibration |
tosihisa | 3:f3796683b4c9 | 18 | while(1) { |
tosihisa | 3:f3796683b4c9 | 19 | compass.read(acc,mag); |
tosihisa | 3:f3796683b4c9 | 20 | hdg = compass.heading(); |
tosihisa | 3:f3796683b4c9 | 21 | hdgV = atan2(acc.y,acc.z) * 180/M_PI; |
tosihisa | 3:f3796683b4c9 | 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 | 3:f3796683b4c9 | 23 | wait(0.1); |
tosihisa | 3:f3796683b4c9 | 24 | } |
tosihisa | 3:f3796683b4c9 | 25 | } |
tosihisa | 3:f3796683b4c9 | 26 |