Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display > 0x3F in my case for a 2004 lcd display
- #include <Adafruit_GPS.h>
- #include <SoftwareSerial.h>
- // Connect the GPS Power pin to 5V
- // Connect the GPS Ground pin to ground
- // Connect the GPS TX (transmit) pin to Digital 4
- // Connect the GPS RX (receive) pin to Digital 3
- SoftwareSerial mySerial(4, 3);
- Adafruit_GPS GPS(&mySerial);
- #define GPSECHO true
- int timezone = +2; // select your time zone
- void setup()
- {
- lcd.init();
- lcd.backlight();
- lcd.setCursor(4,0);
- lcd.print("GPS clock");
- lcd.setCursor(0,1);
- lcd.print("Levente Daradici");
- delay(5000);
- lcd.clear();
- GPS.begin(9600);
- GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
- GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
- GPS.sendCommand(PGCMD_ANTENNA);
- delay(1000);
- }
- uint32_t timer = millis();
- void loop()
- {
- char c = GPS.read();
- if ((c) && (GPSECHO))
- if (GPS.newNMEAreceived())
- {
- if (!GPS.parse(GPS.lastNMEA()))
- return;
- }
- if (timer > millis()) timer = millis();
- if (millis() - timer > 1000) {
- timer = millis();
- lcd.setCursor(4,0);
- int hour = (GPS.hour) + timezone;
- if (hour < 10) { lcd.print('0'); }
- lcd.print(hour, DEC); lcd.print(':');
- if (GPS.minute < 10) { lcd.print('0'); }
- lcd.print(GPS.minute, DEC); lcd.print(':');
- if (GPS.seconds < 10) { lcd.print('0'); }
- lcd.print(GPS.seconds, DEC);
- lcd.setCursor(3,1);
- if (GPS.day < 10) { lcd.print('0'); }
- lcd.print(GPS.day, DEC); lcd.print('.');
- if (GPS.month < 10) { lcd.print('0'); }
- lcd.print(GPS.month, DEC); lcd.print('.');
- lcd.print("20");
- lcd.print(GPS.year, DEC);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement