/*
gps
version 0.3
placa gps modo dline
pines 2 y 3 - rx y tx gps
lcd 13-8
*/
// librerias
#include <NewSoftSerial.h>
#include <TinyGPS.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9,

; // pines de la lcd
#define RXPIN 2 // pines y posicion del interruptor en DLINE
#define TXPIN 3 // rx 2 -- tx 3 velocidad del gps 4800 baudios
#define GPSBAUD 4800
TinyGPS gps; // Create an instance of the TinyGPS object
NewSoftSerial uart_gps(RXPIN, TXPIN); // iniciamos el gps y le asisganmos los pines rx y tx antes asigandos
void getgps(TinyGPS &gps); // This is where you declare prototypes for the functions that will be using the TinyGPS library
// In the setup function, you need to initialize two serial ports; the
// standard hardware serial port (Serial()) to communicate with your
// terminal program an another serial port (NewSoftSerial()) for your
// GPS.
void setup()
{
uart_gps.begin(GPSBAUD); // le pasamos la velocidad de comunicacion al gps
Serial.begin(9600); // le decimos la velocidad de comunicaion con el pc
Serial.println(" Iniciando GPS...");
Serial.println(" varykap 2011");
Serial.println("______________________");
lcd.begin(20, 4); // numero de digitos y filas
lcd.clear();
lcd.setCursor(2,1);
lcd.print("* GPS beta 0.3 *");
lcd.setCursor(3,2);
lcd.print(" varykap 2011");
delay(2000);
lcd.clear();
lcd.setCursor(0,1);
lcd.print(" sincronizando");
lcd.setCursor(0,2);
lcd.print(" satelites...");
}
void loop()
{
while(uart_gps.available()) // While there is data on the RX pin...
{
int c = uart_gps.read(); // load the data into a variable...
if(gps.encode(c)) // if there is a new valid sentence...
{
getgps(gps); // then grab the data, and display on LCD
}
}
}
// The getgps function will get and print the values we want.
void getgps(TinyGPS &gps)
{
// Define the variables that will be used
float latitude, longitude;
// Then call this function
gps.f_get_position(&latitude, &longitude);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("La:");
lcd.print(latitude,5);
lcd.setCursor(0,1);
lcd.print("Lo:");
lcd.print(longitude,5);
int year;
byte month, day, hour, minute, second, hundredths;
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
// Print data and time
int hora=(hour);
hora=(hora+2);
lcd.setCursor(12,1);
lcd.print(hora);
lcd.print(":");
if (minute<10)
{
lcd.print("0");
lcd.print(minute, DEC);
} else if (minute>=10)
{
lcd.print(minute, DEC);
}
lcd.print(":");
if (second<10)
{
lcd.print("0");
lcd.print(second, DEC);
} else if (second>=10)
{
lcd.print(second, DEC);
}
lcd.setCursor(12,0);
lcd.print("V:");
lcd.print(gps.f_speed_kmph());
//lcd.setCursor(12,1);
//lcd.print("C:"); lcd.println(gps.f_course());
float la2=32.658611;
float lo2=-10.718888;
float distance_meters = TinyGPS::distance_between(latitude, longitude, la2, lo2);
lcd.setCursor(0,3);
lcd.print(distance_meters);
/*
Serial.begin(9600);
Serial.print("Latitud : ");
Serial.println(latitude,5);
Serial.print("Longitud : ");
Serial.println(longitude,5);
Serial.print("Distancia: ");
Serial.println(distance_meters);
Serial.print("Velocidad: ");
Serial.println(gps.f_speed_kmph());
Serial.println("______________________");
//delay(1000);
*/
}