GPS1

Dependencies:   GPS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "GPS.h"
00003 
00004 //------------------------------------
00005 // Hyperterminal configuration
00006 // 9600 bauds, 8-bit data, no parity
00007 //------------------------------------
00008 
00009 Serial pc(SERIAL_TX, SERIAL_RX);
00010 GPS gps(PC_10, PC_11);
00011 //Serial gps(PC_10, PC_11);
00012 DigitalOut myled(LED1);
00013 
00014 int main()
00015 {
00016     /*
00017     int i = 1;
00018     pc.printf("Hello World !\n");
00019     while(1) {
00020         wait(1);
00021         pc.printf("This program runs since %d seconds.\n", i++);
00022         myled = !myled;
00023     }
00024     */
00025     
00026     /*
00027     while (true)
00028     {
00029         //int c = gps.getc();
00030         //pc.printf("%c", c);   
00031                 // transfer data from pc to gps
00032         if (pc.readable() && gps.writeable())
00033             gps.putc(pc.getc());
00034         // transfer data from gps to pc
00035         if (gps.readable() && pc.writeable())
00036             pc.putc(gps.getc()); 
00037     }*/
00038     /*
00039     while (true)
00040     {
00041         //double lat  = gps.latitude();
00042         //double lon = gps.longitude();
00043         //double alt  = gps.altitude();
00044         //GPS_Time t;
00045         //gps->timeNow(&t);
00046         //pc.printf("%02d:%02d:%02d %02d/%02d/%04d\r\n", 
00047             //t.hour, t.minute, t.second, t.day, t.month, t.year);
00048         if (gps.sample() == 1)
00049             pc.printf("Success\n");
00050         else
00051             pc.printf("Failed\n");
00052     }
00053     */
00054     myled = 0;
00055     while(1) 
00056     {
00057         if(gps.sample() == 1) 
00058         {
00059             myled = 0;
00060             float latitude = gps.latitude;
00061             float longitude = gps.longitude;
00062             float utc = gps.utc+50000;
00063             pc.printf("latitude: %0.2f, longitude: %0.2f, utc: %f\r\n",latitude,longitude,utc);
00064             wait(1);
00065         } else 
00066         {
00067             myled = 1;
00068             //pc.printf("Not getting GPS\n");
00069         }
00070     }  
00071 }