Adafruit GPS , distance and count footsteps

Dependencies:   mbed SDFileSystem MBed_Adafruit-GPS-Library USBDevice

Revision:
5:da8e5af9d44b
Parent:
4:e87d9fbc4869
Child:
6:f1b3ee4199b7
--- a/main.cpp	Wed Dec 18 07:44:26 2019 +0000
+++ b/main.cpp	Wed Dec 18 14:23:38 2019 +0000
@@ -2,10 +2,15 @@
 #include "mbed.h"
 #include "MBed_Adafruit_GPS.h"
 #include "USBSerial.h"
+#include "SDFileSystem.h" 
 
-USBSerial pc;
+USBSerial pc(0x1f00, 0x2012, 0x0001, false);
 Serial * gps_Serial;
+SDFileSystem sd(PA_7, PA_6, PA_5, PB_6, "sd");   
 
+PwmOut Green(PC_8); //PWM Red LED
+PwmOut Red(PC_6); //PWM Green LED
+PwmOut Blue(PC_9); //PWM Blue LED
 
 int main() {
    
@@ -24,13 +29,16 @@
    myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
    myGPS.sendCommand(PGCMD_ANTENNA);
    
-   pc.printf("Connection established at 115200 baud...\n");
+   FILE *fp = fopen("/sd/GPS_Test.txt", "w");     
+   
+  pc.printf("Connection established at 115200 baud...\n");
    
    wait(1);
    
    refresh_Timer.start();  //starts the clock on the timer
    
-   while(true){
+   while(true)
+   {
        c = myGPS.read();   //queries the GPS
        
        if (c) { } //this line will echo the GPS data if not paused
@@ -46,19 +54,37 @@
        //note if refresh_Time is too low or pc.baud is too low, GPS data may be lost during printing
        if (refresh_Timer.read_ms() >= refresh_Time) {
            refresh_Timer.reset();
+           fprintf(fp,"Time: %d:%d:%d.%u\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds);
+           fprintf(fp,"Date: %d/%d/20%d\n", myGPS.day, myGPS.month, myGPS.year);
+           fprintf(fp,"Fix: %d\n", (int) myGPS.fix);
+           fprintf(fp,"Quality: %d\n\n", (int) myGPS.fixquality);
+           
            pc.printf("Time: %d:%d:%d.%u\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds);
            pc.printf("Date: %d/%d/20%d\n", myGPS.day, myGPS.month, myGPS.year);
            pc.printf("Fix: %d\n", (int) myGPS.fix);
-           pc.printf("Quality: %d\n", (int) myGPS.fixquality);
+           pc.printf("Quality: %d\n\n", (int) myGPS.fixquality);
+           Blue = 0;
            if (myGPS.fix) {
+               fprintf(fp,"Location: %5.2f%c, %5.2f%c\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
+               fprintf(fp,"Speed: %5.2f knots\n", myGPS.speed);
+               fprintf(fp,"Angle: %5.2f\n", myGPS.angle);
+               fprintf(fp,"Altitude: %5.2f\n", myGPS.altitude);
+               fprintf(fp,"Satellites: %d\n\n\n", myGPS.satellites);
+               
                pc.printf("Location: %5.2f%c, %5.2f%c\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
                pc.printf("Speed: %5.2f knots\n", myGPS.speed);
                pc.printf("Angle: %5.2f\n", myGPS.angle);
                pc.printf("Altitude: %5.2f\n", myGPS.altitude);
-               pc.printf("Satellites: %d\n", myGPS.satellites);
+               pc.printf("Satellites: %d\n\n\n", myGPS.satellites);
+               
+               Blue = 1;
+               
            }
+           wait(0.5);
        }
    }
+    fclose(fp);                                                     // Closing the file    
+    if(fp == NULL) { error("Could not open file for write\n"); }    // Error message, if  there is a problem 
 }