Code:-
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
void setup(){
lcd.begin(16, 2);
lcd.print(" GPS CLOCK ");
delay(2000);
lcd.clear();
Serial.begin(9600);
ss.begin(GPSBaud);
smartDelay(0);
}
void loop()
{
printDateTime(gps.date, gps.time);
Serial.println(" ");
// delay(100);
}
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}
static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
if (!d.isValid())
{
Serial.print(F("********** "));
}
else
{
char sz[32];
sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
Serial.print(sz);
}
if (!t.isValid())
{
Serial.print(F("******** "));
}
else
{
char sz[32];
sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
Serial.print(sz);
lcd.setCursor(0, 0);
lcd.print("GPS CLK:");
lcd.print(t.hour());
lcd.print(":");
lcd.print(t.minute());
lcd.print(":");
lcd.print(t.second());
lcd.setCursor(0, 1);
lcd.print("IST CLK:");
int Hour=t.hour()+5;
if(Hour>23)
{
Hour-=24;
}
int Minut=t.minute()+30;
if(Minut>59)
{
Minut-=60;
Hour+=1;
}
lcd.print(Hour);
lcd.print(":");
lcd.print(Minut);
lcd.print(":");
lcd.print(t.second());
}
// printInt(d.age(), d.isValid(), 5);
smartDelay(0);
}
Comments
Post a Comment