Advertisement
pleasedontcode

GPSTime rev_12

Oct 28th, 2023
107
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-29 01:18:16
  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 readGPSData(void);
  35. void displayTimeOnLED(void);
  36. void triggerContactClosure(void);
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t contactClosure_PIN_D2 = 2;
  40.  
  41. /***** DEFINITION OF Software Serial *****/
  42. const uint8_t gpsSerial_PIN_SERIAL_TX_A1 = A1;
  43. const uint8_t gpsSerial_PIN_SERIAL_RX_A0 = A0;
  44. SoftwareSerial gpsSerial(gpsSerial_PIN_SERIAL_RX_A0, gpsSerial_PIN_SERIAL_TX_A1);
  45.  
  46. /***** DEFINITION OF I2C PINS *****/
  47. const uint8_t display_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  48. const uint8_t display_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  49. const uint8_t display_LCD1602I2C_I2C_SLAVE_ADDRESS = 0x27;
  50.  
  51. // Create an object of the MicroNMEA class
  52. MicroNMEA gps;
  53.  
  54. void setup(void)
  55. {
  56.   // Initialize digital output pin for contact closure
  57.   pinMode(contactClosure_PIN_D2, OUTPUT);
  58.  
  59.   // Initialize software serial for GPS module
  60.   gpsSerial.begin(9600);
  61.  
  62.   // Initialize I2C communication for LCD display
  63.   Wire.begin();
  64.   LiquidCrystal_I2C lcd(display_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2);
  65.   lcd.begin(16, 2);
  66.   lcd.backlight();
  67.   lcd.clear();
  68. }
  69.  
  70. void loop(void)
  71. {
  72.   readGPSData();
  73.   displayTimeOnLED();
  74.   triggerContactClosure();
  75. }
  76.  
  77. void readGPSData(void)
  78. {
  79.   // Read NMEA data from GPS module
  80.   while (gpsSerial.available())
  81.   {
  82.     char c = gpsSerial.read();
  83.     // Process the received character using the gps object
  84.     gps.process(c);
  85.   }
  86. }
  87.  
  88. void displayTimeOnLED(void)
  89. {
  90.   // Get the current time from the GPS module using the gps object
  91.   int hour = gps.getHour();
  92.   int minute = gps.getMinute();
  93.   int second = gps.getSecond();
  94.  
  95.   // Display the time on the LCD display
  96.   LiquidCrystal_I2C lcd(display_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2);
  97.   lcd.setCursor(0, 0);
  98.   lcd.print("Time: ");
  99.   lcd.print(hour);
  100.   lcd.print(":");
  101.   if (minute < 10)
  102.   {
  103.     lcd.print("0");
  104.   }
  105.   lcd.print(minute);
  106.   lcd.print(":");
  107.   if (second < 10)
  108.   {
  109.     lcd.print("0");
  110.   }
  111.   lcd.print(second);
  112. }
  113.  
  114. void triggerContactClosure(void)
  115. {
  116.   // Check if minutes and seconds are 00:00 using the gps object
  117.   if (gps.getMinute() == 0 && gps.getSecond() == 0)
  118.   {
  119.     // Trigger contact closure for about 1 second
  120.     digitalWrite(contactClosure_PIN_D2, HIGH);
  121.     delay(1000);
  122.     digitalWrite(contactClosure_PIN_D2, LOW);
  123.   }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement