Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Sparkfun_GPS_Shield by
Revision 2:5eb57d412bf2, committed 2016-01-13
- Comitter:
- VictorMC
- Date:
- Wed Jan 13 15:32:23 2016 +0000
- Parent:
- 1:6bba24a04008
- Commit message:
- 1st version
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 6bba24a04008 -r 5eb57d412bf2 main.cpp
--- a/main.cpp Fri Jul 25 12:25:21 2014 +0000
+++ b/main.cpp Wed Jan 13 15:32:23 2016 +0000
@@ -18,27 +18,69 @@
#include "mbed.h"
#include "SerialGPS.h"
+#include "math.h"
+
+#ifndef M_PI
+ #define M_PI 3.14159265358979323846
+#endif
+
+//Various interruption process
+Ticker toggler; // periodic interrupt routines
+//Timer debounce; // define debounce timer
/** On many platforms USBTX/USBRX overlap with serial on D1/D0 pins and enabling the below will interrupt the communication.
* You can use an LCD display to print the values or store them on an SD card etc.
*/
-//Serial pc(USBTX, USBRX);
+Serial pc(USBTX, USBRX);
/**
- * D1 - TX pin (RX on the GPS module side)
- * D0 - RX pin (TX on the GPS module side)
- * 4800 - GPS baud rate
+ * PC_10 - TX pin (RX on the GPS module side)
+ * PC_11 - RX pin (TX on the GPS module side)
+ * 9600 - GPS baud rate
*/
-SerialGPS gps(D1, D0, 4800);
+SerialGPS gps(PC_10, PC_11, 9600);
+
+void toggle_gps(){
+ int i=0;
+ while(1){
+ //pc.printf("gps.sample?\n\r");
+ if (gps.sample()) {
+ i++;
+ //pc.printf("true\n\r");
+ pc.printf("sats %d, lat %f, lont %f, alt %f, geoid %f, time %f\n\r", gps.sats, gps.latitude, gps.longitude, gps.alt, gps.geoid, gps.time);
+ break;
+ }
+ }
+
+}
-DigitalOut myled(LED1);
+float DegToRad(float valDeg){
+ return M_PI*valDeg/180;
+}
+
+double distance(float rxLat, float rxLong){
+ double a=0, c=0;
+ int R=6371000;
+
+ double deltaLong=abs(DegToRad(rxLong)-DegToRad(gps.longitude));
+ double deltaLat=abs(DegToRad(rxLat)-DegToRad(gps.latitude));
+
+ a=sin(deltaLat/2)*sin(deltaLat/2)+cos((double)DegToRad(rxLat))*cos((double)DegToRad(gps.latitude))*sin(deltaLong/2)*sin(deltaLong/2);
+ c=2*atan2(sqrt(a), sqrt(1-a));
+
+ return R*c;
+ }
int main() {
- while (1) {
- if (gps.sample()) {
- myled = myled ? 0 : 1;
- printf("sats %d, long %f, lat %f, alt %f, geoid %f, time %f\n\r", gps.sats, gps.longitude, gps.latitude, gps.alt, gps.geoid, gps.time);
- wait(1);
- }
- }
+ /*
+ int i=0,k;
+ double distance;
+ float sleep=20.0;
+ toggler.attach(&toggle_gps,sleep);
+ */
+ gps.latitude=43.615659;
+ gps.longitude=7.072609;
+ pc.printf("La distance entre les deux points est de: %f", distance(43.616541,7.070429));
+ while(1);
+
}
\ No newline at end of file
diff -r 6bba24a04008 -r 5eb57d412bf2 mbed.bld --- a/mbed.bld Fri Jul 25 12:25:21 2014 +0000 +++ b/mbed.bld Wed Jan 13 15:32:23 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c \ No newline at end of file
