Allan Li
/
Final_Demo
GPS and Compass update every1 sec
main.cpp@1:ce62180e1576, 2013-12-02 (annotated)
- Committer:
- airaylee
- Date:
- Mon Dec 02 22:21:20 2013 +0000
- Revision:
- 1:ce62180e1576
- Parent:
- 0:b28303f602dc
- Child:
- 2:e70394e9c959
Ver1.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
airaylee | 0:b28303f602dc | 1 | #include "HMC6352.h" |
airaylee | 0:b28303f602dc | 2 | #include "mbed.h" |
airaylee | 0:b28303f602dc | 3 | #include "GPS.h" |
airaylee | 0:b28303f602dc | 4 | |
airaylee | 0:b28303f602dc | 5 | //HMC6352 use an I2C interface so we here have scl-p27 and sda-28 |
airaylee | 1:ce62180e1576 | 6 | //BR-355 GPS use serial port p14-RX |
airaylee | 0:b28303f602dc | 7 | HMC6352 compass(p28, p27); |
airaylee | 0:b28303f602dc | 8 | Serial pc(USBTX, USBRX); |
airaylee | 1:ce62180e1576 | 9 | GPS gps(p13, p14); |
airaylee | 0:b28303f602dc | 10 | |
airaylee | 0:b28303f602dc | 11 | int main() { |
airaylee | 1:ce62180e1576 | 12 | pc.printf("Starting\n"); |
airaylee | 0:b28303f602dc | 13 | //Continuous mode, periodic set/reset, 20Hz measurement rate. |
airaylee | 0:b28303f602dc | 14 | compass.setOpMode(HMC6352_CONTINUOUS, 1, 20); |
airaylee | 0:b28303f602dc | 15 | while (1) { |
airaylee | 0:b28303f602dc | 16 | wait(1); |
airaylee | 1:ce62180e1576 | 17 | pc.printf("compass:%f,", compass.sample() / 10.0); |
airaylee | 0:b28303f602dc | 18 | if(gps.sample()){ |
airaylee | 1:ce62180e1576 | 19 | pc.printf("GPS:%f,%f\n", gps.longitude, gps.latitude); |
airaylee | 0:b28303f602dc | 20 | } |
airaylee | 0:b28303f602dc | 21 | else{ |
airaylee | 1:ce62180e1576 | 22 | pc.printf("No\n"); |
airaylee | 0:b28303f602dc | 23 | } |
airaylee | 0:b28303f602dc | 24 | } |
airaylee | 0:b28303f602dc | 25 | } |
airaylee | 0:b28303f602dc | 26 |