Allan Li
/
Final_Demo
GPS and Compass update every1 sec
main.cpp@2:e70394e9c959, 2013-12-03 (annotated)
- Committer:
- airaylee
- Date:
- Tue Dec 03 21:10:11 2013 +0000
- Revision:
- 2:e70394e9c959
- Parent:
- 1:ce62180e1576
- Child:
- 3:5eba63777267
ver1.3;
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 | 2:e70394e9c959 | 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 | 2:e70394e9c959 | 17 | pc.printf("%f,", compass.sample() / 10.0); |
airaylee | 0:b28303f602dc | 18 | if(gps.sample()){ |
airaylee | 2:e70394e9c959 | 19 | pc.printf("%f,%f\n", gps.longitude, gps.latitude); |
airaylee | 0:b28303f602dc | 20 | } |
airaylee | 0:b28303f602dc | 21 | else{ |
airaylee | 2:e70394e9c959 | 22 | pc.printf("0,0\n"); |
airaylee | 0:b28303f602dc | 23 | } |
airaylee | 0:b28303f602dc | 24 | } |
airaylee | 0:b28303f602dc | 25 | } |
airaylee | 0:b28303f602dc | 26 |