Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <TinyGPS.h>;
  2. #include <SoftwareSerial.h>;
  3.  
  4. SoftwareSerial GPS(3,4);
  5. TinyGPS gps;
  6.  
  7.  
  8. long lat, lon;
  9. float LAT, LON;
  10.  
  11. void setup(){
  12.   GPS.begin(9600);
  13.   Serial.begin(115200);
  14. }
  15.  
  16. void loop(){
  17.   getGPS();
  18.   // data o pozovo sou ve stotisícinách stupnů
  19.   // proto dělíme 100000
  20.   // a vypíšeme na serial monitor
  21.   Serial.print("Latitude : ");
  22.   Serial.print(LAT/100000,7);
  23.   Serial.print(" :: Longitude : ");
  24.   Serial.println(LON/100000,7);
  25. }
  26.  
  27. void getGPS(){
  28.   bool newdata = false;
  29.   unsigned long start = millis();
  30.   // Update každou sekundu
  31.   while (millis() - start < 1000)
  32.   {
  33.     if (feedgps ()){
  34.       newdata = true;
  35.     }
  36.   }
  37.   // když jsou nová data
  38.   if (newdata)
  39.   {    
  40.     // ******************************
  41.     // toto je ta hlavní funkce
  42.     // zjistí data o pozici
  43.     gps.get_position(&lat, &lon);
  44.     // *****************************
  45.    
  46.     LAT = lat;
  47.     LON = lon;
  48.     // čekací funkce
  49.     feedgps();
  50.   }
  51. }
  52.  
  53. // Tato funkce zastaví program a čeká až skončí komunikace s modulem
  54. // Program by mohl házet chyby nebo třeba nesmyslné znak na displej v případě
  55. // probíhající komunikace s modulem
  56. bool feedgps(){
  57.   while (GPS.available())
  58.   {
  59.     if (gps.encode(GPS.read()))
  60.     return true;
  61.   }
  62.   return 0;
  63. }