#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
float aimlat = 0 ;
float aimlng = 0 ;
static const int RXPin = 8, TXPin = 9;
static const uint32_t GPSBaud = 9600;
float lat ;
float lng ;
float mesafe = 0 ;
float mes1 = 0 ;
float mes2 = 0 ;
float a = 0 ;
float latdif = 0 ;
float lngdif = 0 ;
//son millis değerini tutacağımız değişken
unsigned long lastTime = 0 ;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
void setup()
{
lcd.begin(16, 2);
Serial.begin(115200);
ss.begin(GPSBaud);
lcd.print(" WELCOME ");
delay(2000);
lcd.clear();
}
void loop()
{
aimlat = 37.06173 ;
aimlng = 35.35334 ;
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0)
if (gps.encode(ss.read()))
{
latdif = (aimlat - gps.location.lat())*111.1949 ; //km
a=radians((aimlng + gps.location.lng()) / 2) ;
lngdif = 111.1949*((aimlng - gps.location.lng())*(cos(a))) ;
mes1 = pow(latdif, 2);
mes2 = pow(lngdif, 2);
mesafe = sqrt(mes1 + mes2);
}
displayInfo();
if (millis() > 5000 && gps.charsProcessed() < 10)
{
lcd.print(F("No GPS detected"));
while(true);
}
}
void displayInfo()
{
if (gps.location.isValid())
{
lcd.setCursor(0,0);
lcd.print("Lat=");
lcd.print(gps.location.lat(), 5);
lcd.setCursor(0,1);
lcd.print("Lng=");
lcd.print(gps.location.lng(), 5);
delay(3000) ;
lcd.clear();
// deneme bolgesi
//lcd.setCursor(0,0);
//lcd.print("a=");
//lcd.print( a ,5);
//delay(1000) ;
//lcd.clear();
//lcd.setCursor(0,0);
// lcd.print("aimlat=");
//lcd.print( aimlat ,5);
// lcd.setCursor(0,1);
//lcd.print("aimlng=");
//lcd.print( aimlng , 5);
//delay(5000) ;
//lcd.clear();
//lcd.setCursor(0,0);
//lcd.print("latdif=");
//lcd.print(latdif, 5);
//lcd.setCursor(0,1);
//lcd.print("lngdif=");
//lcd.print(lngdif , 5);
//delay(5000) ;
//lcd.clear();
//lcd.setCursor(0,0);
//lcd.print("mes1=");
//lcd.print( mes1, 5);
//lcd.setCursor(0,1);
//lcd.print("mes2=");
//lcd.print( mes2, 5);
//delay(5000) ;
//lcd.clear();
//lcd.setCursor(0,0);
//lcd.print(" erasing... ");
// lcd.clear();
// deneme bitis
lcd.print("mesafe= ");
lcd.print(mesafe, 6);
delay(5000) ;
lcd.clear();
}
else
{
lcd.setCursor(0,0);
lcd.print(" INVALID ");
lcd.clear () ;
}
}
//yeryüzü ortalama çevresi=2x6371000mxpi==40030173m
//delta(d)enlem=(40030173xenlemfarki)/360=111194.9mxenlemfarki