Advertisement
pleasedontcode

GPSTime rev_08

Oct 18th, 2023
104
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-10-18 20:34:01
  15.     - Source Code generated by: Francesco Alessandro
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <Wire.h>
  21. #include <SoftwareSerial.h>
  22. #include <LiquidCrystal_I2C.h>
  23. #include <MicroNMEA.h>
  24.  
  25. /****** SYSTEM REQUIREMENT 1 *****/
  26. /* Reads NMEA 8bit data from GPS module. Reads hours */
  27. /* minutes, seconds and Display h, m, s on 6x 7seg */
  28. /* LED display. When mins and secs are 00 00, */
  29. /* contact closure for about 1 sec. */
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void displayTime(uint8_t hours, uint8_t minutes, uint8_t seconds);
  35. void triggerContactClosure();
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t contactClosure_PIN_D2 = 2;
  39.  
  40. /***** DEFINITION OF Software Serial *****/
  41. const uint8_t gpsSerial_PIN_SERIAL_TX_A1 = A1;
  42. const uint8_t gpsSerial_PIN_SERIAL_RX_A0 = A0;
  43. SoftwareSerial gpsSerial(gpsSerial_PIN_SERIAL_RX_A0, gpsSerial_PIN_SERIAL_TX_A1);
  44.  
  45. /***** DEFINITION OF I2C PINS *****/
  46. const uint8_t display_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  47. const uint8_t display_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  48. const uint8_t display_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  49.  
  50. /***** DEFINITION OF LCD DISPLAY *****/
  51. LiquidCrystal_I2C lcd(display_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2);
  52.  
  53. /***** DEFINITION OF NMEA PARSER *****/
  54. MicroNMEA nmea;
  55.  
  56. void setup(void)
  57. {
  58.   // Initialize digital output pin for contact closure
  59.   pinMode(contactClosure_PIN_D2, OUTPUT);
  60.  
  61.   // Initialize serial communication with GPS module
  62.   gpsSerial.begin(9600);
  63.  
  64.   // Initialize I2C communication with LCD display
  65.   Wire.begin();
  66.   lcd.begin(16, 2);
  67.   lcd.backlight();
  68. }
  69.  
  70. void loop(void)
  71. {
  72.   // Read NMEA data from GPS module
  73.   while (gpsSerial.available()) {
  74.     char c = gpsSerial.read();
  75.     nmea.process(c);
  76.   }
  77.  
  78.   // Check if a valid fix is available
  79.   if (nmea.isValid()) {
  80.     // Get the hours, minutes, and seconds from the GPS module
  81.     uint8_t hours = nmea.getHour();
  82.     uint8_t minutes = nmea.getMinute();
  83.     uint8_t seconds = nmea.getSecond();
  84.  
  85.     // Display the time on the LCD display
  86.     displayTime(hours, minutes, seconds);
  87.  
  88.     // Check if minutes and seconds are both 00
  89.     if (minutes == 0 && seconds == 0) {
  90.       // Trigger the contact closure for about 1 second
  91.       triggerContactClosure();
  92.     }
  93.   }
  94. }
  95.  
  96. void displayTime(uint8_t hours, uint8_t minutes, uint8_t seconds)
  97. {
  98.   // Clear the LCD display
  99.   lcd.clear();
  100.  
  101.   // Set the cursor to the first line
  102.   lcd.setCursor(0, 0);
  103.  
  104.   // Display the hours, minutes, and seconds on the LCD display
  105.   lcd.print("Time: ");
  106.   lcd.print(hours);
  107.   lcd.print(":");
  108.   if (minutes < 10) {
  109.     lcd.print("0");
  110.   }
  111.   lcd.print(minutes);
  112.   lcd.print(":");
  113.   if (seconds < 10) {
  114.     lcd.print("0");
  115.   }
  116.   lcd.print(seconds);
  117. }
  118.  
  119. void triggerContactClosure()
  120. {
  121.   // Trigger the contact closure for about 1 second
  122.   digitalWrite(contactClosure_PIN_D2, HIGH);
  123.   delay(1000);
  124.   digitalWrite(contactClosure_PIN_D2, LOW);
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement