Advertisement
redsees

Untitled

Sep 30th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. http://arduiniana.org/TinyGPS/TinyGPS10.zip
  2. http://arduiniana.org/libraries/newsoftserial/
  3.  
  4. #include<TinyGPS.h>
  5. #include<NewSoftSerial.h>
  6. unsigned long fix_age;
  7. NewSoftSerial GPS(2,3);
  8. TinyGPS gps;
  9. void gpsdump(TinyGPS &gps);
  10. bool feedgps();
  11. void getGPS();
  12. long lat,lon;
  13. float LAT,LON;
  14. void setup()
  15. {
  16. GPS.begin(9600);
  17. Serial.begin(115200);
  18. }
  19.  
  20. void loop()
  21. {
  22. long lat,lon;
  23. unsigned long fix_age,time,date,speed,course;
  24. unsigned long chars;
  25. unsigned short sentences,failed_checksum;
  26. gps.get_position(&lat,&lon,&fix_age);
  27. getGPS();
  28. Serial.print("Latitude : ");
  29. Serial.print(LAT/100000,7);
  30. Serial.print(" :: Longitude : ");
  31. Serial.println(LON/100000,7);
  32. }
  33.  
  34. void getGPS(){
  35. bool newdata=false;
  36. unsigned long start = millis();
  37. while(millis() - start < 1000)
  38. {
  39. if(feedgps()){
  40. newdata = true;
  41. }
  42. }
  43. if(newdata)
  44. {
  45. gpsdump(gps);
  46. }
  47. }
  48.  
  49. bool feedgps(){
  50. while(GPS.available())
  51. {
  52. if(gps.encode(GPS.read()))
  53. return true;
  54. }
  55. return 0;
  56. }
  57.  
  58. void gpsdump(TinyGPS &gps)
  59. {
  60. gps.get_position(&lat,&lon);
  61. LAT = lat;
  62. LON = lon;
  63. {
  64. feedgps();
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement