This use a GPS data to provide time and altitude on an LCD Screen.
/* MarksGPS_Clock shows time on top row
- Altitude and and number of Satelites on bottom row.
- Finished Oct.9 2013, Mark R. Matthias
*/
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
TinyGPS gps;
SoftwareSerial a(0,1);
static void b(TinyGPS &gps);
static bool c();
static void d(TinyGPS &gps);
void setup()
{
Serial.begin(9600);
a.begin(4800);
Serial.println("Using MarksGPS_Clock 10/9/2013");
Serial.println("Go to line 55 to adjust for Time Zone and Daylight Savings");
}
/* Go to Line 55 to adjust for Timezone/Daylight Savings
- The circuit:
- LCD RS pin to digital pin 12
- LCD Enable pin to digital pin 11
- LCD D4 pin to digital pin 5
- LCD D5 pin to digital pin 4
- LCD D6 pin to digital pin 3
- LCD D7 pin to digital pin 2
- LCD R/W pin to ground
- 10K resistor: one end to +5V and one to ground and (mddle pin) wiper to LCD VO pin (pin 3)
- add: pin 16 (LED-)to ground (last pin of LCD)
- add pin 15 (Led+)with 220 Ohm resistor (next to last lcd pin)
- add forst pin of LCD to ground
*/
void loop()
{
bool newdata = false;
unsigned long start = millis();
// Every second we print an update
while (millis() - start < 970)
{
if (c())
newdata = true;
}
b(gps);
}
static void b(TinyGPS &gps)
{
d(gps);
}
static void d(TinyGPS &gps)
{
int TimeZn (8);
float alt;
float flat, flon;
unsigned long ag;
gps.f_get_position(&flat, &flon, &ag);
Serial.print("Latitude:" );
Serial.print(flat);
Serial.print (" Longitude:") ;
Serial.print (flon);
Serial.print (" age = ");
Serial.println (ag);
alt=gps.f_altitude();
alt=alt*3.28084;
int atl (alt);
int sats;
sats=(gps.satellites());
int year;
int h;
byte month, day, hour, minute, second, hundredths;
unsigned long age;
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
lcd.begin(16,2);
lcd.setCursor(0,0);
if (ag >= 3000){
lcd.print("No Signal..... ");
lcd.setCursor(0,1);
lcd.print("Chk GPS connect ");
}
else
{
char lq[16];
if (hour >= TimeZn) hour=hour-TimeZn;
else hour=hour+12-TimeZn;
if (hour >12) hour=hour-12;
// Need to figure out how to toggle between night and day mode.
//This is Day Mode
sprintf(lq, "%02d:%02d:%02d ",
hour, minute, second);
lcd.setCursor(0,1);
lcd.print("Alt: ");
lcd.print(atl) ;
lcd.print("ft ");
lcd.print("S:");
lcd.print(sats);
lcd.setCursor(0,0);
lcd.print("Time: ");
lcd.print(lq);
}
c();
}
static bool c()
{
while (a.available())
{
if (gps.encode(a.read()))
return true;
}
return false;
}