Advertisement
marwin7777

Untitled

Mar 10th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. #include <TinyGPS++.h>
  2. #include <SoftwareSerial.h>
  3. #include <SD.h>
  4. #include <LiquidCrystal.h>
  5. static const int RXPin = 5, TXPin = 3;
  6. static const uint32_t GPSBaud = 9600;
  7. /*const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 6, d7 = 7;
  8. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);*/
  9. File myFile;
  10. TinyGPSPlus gps;
  11. String nazwa_pliku;
  12. SoftwareSerial ss(RXPin, TXPin);
  13.  
  14. void setup()
  15. {
  16. Serial.begin(9600);
  17. // wyswietlLCD();tu jeszcze dziala
  18. ss.begin(GPSBaud);
  19. sprawdzKarte();
  20. // wyswietlLCD();tu juz nie dziala
  21. nadajNazwePliku();
  22. // wyswietlLCD();i tu tez nie dziala
  23. }
  24.  
  25. void loop()
  26. {
  27. while (ss.available() > 0)
  28. if (gps.encode(ss.read()))
  29. { wyswietlDane();
  30. zapiszDaneNaKarte();
  31. sprawdzPodlaczenia();
  32. }
  33. }
  34.  
  35. void wyswietlDane()
  36. {
  37. Serial.print(F("Location: "));
  38. if (gps.location.isValid())
  39. {
  40. Serial.print(gps.location.lat(), 6);
  41. Serial.print(F(","));
  42. Serial.print(gps.location.lng(), 6);
  43. }
  44. else
  45. {
  46. Serial.print(F("INVALID"));
  47. }
  48.  
  49. Serial.print(F(" Date/Time: "));
  50. if (gps.date.isValid())
  51. {
  52. Serial.print(gps.date.month());
  53. Serial.print(F("/"));
  54. Serial.print(gps.date.day());
  55. Serial.print(F("/"));
  56. Serial.print(gps.date.year());
  57. }
  58. else
  59. {
  60. Serial.print(F("INVALID"));
  61. }
  62.  
  63. Serial.print(F(" "));
  64. if (gps.time.isValid())
  65. {
  66. if (gps.time.hour() < 10) Serial.print(F("0"));
  67. Serial.print(gps.time.hour());
  68. Serial.print(F(":"));
  69. if (gps.time.minute() < 10) Serial.print(F("0"));
  70. Serial.print(gps.time.minute());
  71. Serial.print(F(":"));
  72. if (gps.time.second() < 10) Serial.print(F("0"));
  73. Serial.print(gps.time.second());
  74. Serial.print(F("."));
  75. if (gps.time.centisecond() < 10) Serial.print(F("0"));
  76. Serial.print(gps.time.centisecond());
  77. }
  78. else
  79. {
  80. Serial.print(F("INVALID"));
  81. }
  82.  
  83. Serial.println();
  84.  
  85. czekaj();
  86. }
  87. void wyswietlLCD()
  88. {
  89. const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 6, d7 = 7;
  90. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  91. lcd.begin(16,2);
  92. lcd.clear();
  93. lcd.setCursor(0,0);
  94. czekaj();
  95. lcd.print("aaa");
  96. czekaj();
  97. lcd.print(" eee");
  98. czekaj();
  99. lcd.setCursor(1,1);
  100. lcd.print("bbb");
  101. czekaj();
  102. lcd.print(" ccc");
  103. czekaj();
  104. lcd.print(" ddd");
  105. }
  106. void czekaj()
  107. {
  108. delay(1000);
  109. }
  110. void sprawdzKarte()
  111. {
  112. if (!SD.begin(4))
  113. {Serial.println("Nie wykryto karty!!");
  114. return;}
  115. else
  116. Serial.println("Karta microSD jest gotowa");
  117. }
  118. void nadajNazwePliku()
  119. {
  120. while (gps.time.minute()==0||gps.time.hour()==0)
  121. {
  122. while (ss.available() > 0)
  123. if (gps.encode(ss.read()))
  124. {;}
  125. }
  126. String godz,minu,rok, mies, dzie;
  127. godz=String(gps.time.hour());
  128. if (gps.time.hour()<10) godz="0"+godz;
  129. minu=String(gps.time.minute());
  130. if (gps.time.minute()<10) minu="0"+minu;
  131. rok=String(gps.date.year()%100);
  132. mies=String(gps.date.month());
  133. if (gps.date.month()<10) mies="0"+mies;
  134. dzie=String(gps.date.day());
  135. if (gps.date.day()<10) dzie="0"+dzie;
  136. nazwa_pliku=mies+dzie+godz+minu+".txt";
  137. Serial.println(nazwa_pliku);
  138. }
  139.  
  140. void zapiszDaneNaKarte(){
  141. myFile=SD.open(nazwa_pliku, FILE_WRITE);
  142. myFile.print("szerokosc: ");
  143. myFile.print(gps.location.lat(),6);
  144. myFile.print(", dlugosc: ");
  145. myFile.print(gps.location.lng(),6);
  146. myFile.print(", data: ");
  147. if (gps.date.day()<10) myFile.print("0");
  148. myFile.print(gps.date.day());
  149. myFile.print("/");
  150. if (gps.date.month()<10) myFile.print("0");
  151. myFile.print(gps.date.month());
  152. myFile.print("/");
  153. myFile.print(gps.date.year());
  154. myFile.print(", czas: ");
  155. myFile.print(gps.time.hour());
  156. myFile.print(":");
  157. if (gps.time.minute()<10) myFile.print("0");
  158. myFile.print(gps.time.minute());
  159. myFile.print(":");
  160. if (gps.time.second()<10) myFile.print("0");
  161. myFile.println(gps.time.second());
  162. myFile.close();}
  163.  
  164. void sprawdzPodlaczenia(){
  165. if (millis() > 5000 && gps.charsProcessed() < 10)
  166. {
  167. Serial.println(F("No GPS detected: check wiring."));
  168. while(true);
  169. }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement