Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TinyGPS++.h>
- #include <SoftwareSerial.h>
- #include <SD.h>
- #include <LiquidCrystal.h>
- static const int RXPin = 5, TXPin = 3;
- static const uint32_t GPSBaud = 9600;
- /*const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 6, d7 = 7;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);*/
- File myFile;
- TinyGPSPlus gps;
- String nazwa_pliku;
- SoftwareSerial ss(RXPin, TXPin);
- void setup()
- {
- Serial.begin(9600);
- // wyswietlLCD();tu jeszcze dziala
- ss.begin(GPSBaud);
- sprawdzKarte();
- // wyswietlLCD();tu juz nie dziala
- nadajNazwePliku();
- // wyswietlLCD();i tu tez nie dziala
- }
- void loop()
- {
- while (ss.available() > 0)
- if (gps.encode(ss.read()))
- { wyswietlDane();
- zapiszDaneNaKarte();
- sprawdzPodlaczenia();
- }
- }
- void wyswietlDane()
- {
- Serial.print(F("Location: "));
- if (gps.location.isValid())
- {
- Serial.print(gps.location.lat(), 6);
- Serial.print(F(","));
- Serial.print(gps.location.lng(), 6);
- }
- else
- {
- Serial.print(F("INVALID"));
- }
- Serial.print(F(" Date/Time: "));
- if (gps.date.isValid())
- {
- Serial.print(gps.date.month());
- Serial.print(F("/"));
- Serial.print(gps.date.day());
- Serial.print(F("/"));
- Serial.print(gps.date.year());
- }
- else
- {
- Serial.print(F("INVALID"));
- }
- Serial.print(F(" "));
- if (gps.time.isValid())
- {
- if (gps.time.hour() < 10) Serial.print(F("0"));
- Serial.print(gps.time.hour());
- Serial.print(F(":"));
- if (gps.time.minute() < 10) Serial.print(F("0"));
- Serial.print(gps.time.minute());
- Serial.print(F(":"));
- if (gps.time.second() < 10) Serial.print(F("0"));
- Serial.print(gps.time.second());
- Serial.print(F("."));
- if (gps.time.centisecond() < 10) Serial.print(F("0"));
- Serial.print(gps.time.centisecond());
- }
- else
- {
- Serial.print(F("INVALID"));
- }
- Serial.println();
- czekaj();
- }
- void wyswietlLCD()
- {
- const int rs = 8, en = 9, d4 = 10, d5 = 11, d6 = 6, d7 = 7;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- lcd.begin(16,2);
- lcd.clear();
- lcd.setCursor(0,0);
- czekaj();
- lcd.print("aaa");
- czekaj();
- lcd.print(" eee");
- czekaj();
- lcd.setCursor(1,1);
- lcd.print("bbb");
- czekaj();
- lcd.print(" ccc");
- czekaj();
- lcd.print(" ddd");
- }
- void czekaj()
- {
- delay(1000);
- }
- void sprawdzKarte()
- {
- if (!SD.begin(4))
- {Serial.println("Nie wykryto karty!!");
- return;}
- else
- Serial.println("Karta microSD jest gotowa");
- }
- void nadajNazwePliku()
- {
- while (gps.time.minute()==0||gps.time.hour()==0)
- {
- while (ss.available() > 0)
- if (gps.encode(ss.read()))
- {;}
- }
- String godz,minu,rok, mies, dzie;
- godz=String(gps.time.hour());
- if (gps.time.hour()<10) godz="0"+godz;
- minu=String(gps.time.minute());
- if (gps.time.minute()<10) minu="0"+minu;
- rok=String(gps.date.year()%100);
- mies=String(gps.date.month());
- if (gps.date.month()<10) mies="0"+mies;
- dzie=String(gps.date.day());
- if (gps.date.day()<10) dzie="0"+dzie;
- nazwa_pliku=mies+dzie+godz+minu+".txt";
- Serial.println(nazwa_pliku);
- }
- void zapiszDaneNaKarte(){
- myFile=SD.open(nazwa_pliku, FILE_WRITE);
- myFile.print("szerokosc: ");
- myFile.print(gps.location.lat(),6);
- myFile.print(", dlugosc: ");
- myFile.print(gps.location.lng(),6);
- myFile.print(", data: ");
- if (gps.date.day()<10) myFile.print("0");
- myFile.print(gps.date.day());
- myFile.print("/");
- if (gps.date.month()<10) myFile.print("0");
- myFile.print(gps.date.month());
- myFile.print("/");
- myFile.print(gps.date.year());
- myFile.print(", czas: ");
- myFile.print(gps.time.hour());
- myFile.print(":");
- if (gps.time.minute()<10) myFile.print("0");
- myFile.print(gps.time.minute());
- myFile.print(":");
- if (gps.time.second()<10) myFile.print("0");
- myFile.println(gps.time.second());
- myFile.close();}
- void sprawdzPodlaczenia(){
- if (millis() > 5000 && gps.charsProcessed() < 10)
- {
- Serial.println(F("No GPS detected: check wiring."));
- while(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement