Advertisement
pleasedontcode

GPSTime rev_116

Nov 24th, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: GPSTime
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-11-24 23:41:51
  15.     - Source Code generated by: Francesco Alessandro
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <SoftwareSerial.h>
  21. #include <Wire.h>
  22. #include <MicroNMEA.h>
  23. #include <LiquidCrystal_I2C.h>
  24.  
  25. /****** SYSTEM REQUIREMENT 1 *****/
  26. // Reads hour, minutes and seconds from GPS module using MicroNMEA library.
  27. // Display hours, minutes and seconds on a 6-digit 7-segment LED display.
  28. // Activates contact closure for about 1 second when minutes and seconds are 00 00.
  29.  
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup();
  33. void loop();
  34.  
  35. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  36. const uint8_t CONTACT_CLOSURE_PIN = 7;
  37.  
  38. /***** DEFINITION OF Software Serial *****/
  39. const uint8_t GPS_MODULE_PIN_RX = A1;
  40. const uint8_t GPS_MODULE_PIN_TX = A0;
  41. SoftwareSerial GPS_MODULE(GPS_MODULE_PIN_RX, GPS_MODULE_PIN_TX);
  42.  
  43. /***** DEFINITION OF I2C PINS *****/
  44. const uint8_t LCD_I2C_PIN_SDA = A4;
  45. const uint8_t LCD_I2C_PIN_SCL = A5;
  46. const uint8_t LCD_I2C_SLAVE_ADDRESS = 0x27; // I2C slave address of the LCD module
  47.  
  48. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  49. MicroNMEA nmea;
  50. LiquidCrystal_I2C lcd(LCD_I2C_SLAVE_ADDRESS, 16, 2);
  51.  
  52. void setup() {
  53.   // Set contact closure pin as output
  54.   pinMode(CONTACT_CLOSURE_PIN, OUTPUT);
  55.  
  56.   // Initialize the GPS module
  57.   GPS_MODULE.begin(9600);
  58.  
  59.   // Initialize the LCD module
  60.   lcd.init();
  61.  
  62.   // Turn on the backlight
  63.   lcd.backlight();
  64.  
  65.   // Clear the LCD display
  66.   lcd.clear();
  67.  
  68.   // Print initial message on LCD
  69.   lcd.print("GPS Time: ");
  70. }
  71.  
  72. void loop() {
  73.   if (GPS_MODULE.available()) {
  74.     char c = GPS_MODULE.read();
  75.    
  76.     // Process the GPS data
  77.     nmea.process(c);
  78.   }
  79.  
  80.   // Check if valid time data is available
  81.   if (nmea.getYear() != 0) {
  82.     // Display the time on the LCD
  83.     lcd.setCursor(10, 0);
  84.     lcd.print(nmea.getHour());
  85.     lcd.print(":");
  86.     lcd.print(nmea.getMinute());
  87.     lcd.print(":");
  88.     lcd.print(nmea.getSecond());
  89.  
  90.     // Check if minutes and seconds are 00:00
  91.     if (nmea.getMinute() == 0 && nmea.getSecond() == 0) {
  92.       // Activate contact closure for 1 second
  93.       digitalWrite(CONTACT_CLOSURE_PIN, HIGH);
  94.       delay(1000);
  95.       digitalWrite(CONTACT_CLOSURE_PIN, LOW);
  96.     }
  97.   }
  98.  
  99.   // Adjust the delay if needed
  100.   delay(1000);
  101. }
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement