/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: GPSTime
- Source Code compiled for: Arduino Uno
- Source Code created on: 2023-11-24 23:41:51
- Source Code generated by: Francesco Alessandro
********* Pleasedontcode.com **********/
/****** DEFINITION OF LIBRARIES *****/
#include
#include
#include
#include
#include
/****** SYSTEM REQUIREMENT 1 *****/
// Reads hour, minutes and seconds from GPS module using MicroNMEA library.
// Display hours, minutes and seconds on a 6-digit 7-segment LED display.
// Activates contact closure for about 1 second when minutes and seconds are 00 00.
/****** FUNCTION PROTOTYPES *****/
void setup();
void loop();
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t CONTACT_CLOSURE_PIN = 7;
/***** DEFINITION OF Software Serial *****/
const uint8_t GPS_MODULE_PIN_RX = A1;
const uint8_t GPS_MODULE_PIN_TX = A0;
SoftwareSerial GPS_MODULE(GPS_MODULE_PIN_RX, GPS_MODULE_PIN_TX);
/***** DEFINITION OF I2C PINS *****/
const uint8_t LCD_I2C_PIN_SDA = A4;
const uint8_t LCD_I2C_PIN_SCL = A5;
const uint8_t LCD_I2C_SLAVE_ADDRESS = 0x27; // I2C slave address of the LCD module
/****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
MicroNMEA nmea;
LiquidCrystal_I2C lcd(LCD_I2C_SLAVE_ADDRESS, 16, 2);
void setup() {
// Set contact closure pin as output
pinMode(CONTACT_CLOSURE_PIN, OUTPUT);
// Initialize the GPS module
GPS_MODULE.begin(9600);
// Initialize the LCD module
lcd.init();
// Turn on the backlight
lcd.backlight();
// Clear the LCD display
lcd.clear();
// Print initial message on LCD
lcd.print("GPS Time: ");
}
void loop() {
if (GPS_MODULE.available()) {
char c = GPS_MODULE.read();
// Process the GPS data
nmea.process(c);
}
// Check if valid time data is available
if (nmea.getYear() != 0) {
// Display the time on the LCD
lcd.setCursor(10, 0);
lcd.print(nmea.getHour());
lcd.print(":");
lcd.print(nmea.getMinute());
lcd.print(":");
lcd.print(nmea.getSecond());
// Check if minutes and seconds are 00:00
if (nmea.getMinute() == 0 && nmea.getSecond() == 0) {
// Activate contact closure for 1 second
digitalWrite(CONTACT_CLOSURE_PIN, HIGH);
delay(1000);
digitalWrite(CONTACT_CLOSURE_PIN, LOW);
}
}
// Adjust the delay if needed
delay(1000);
}