Advertisement
pleasedontcode

GPSTime rev_114

Nov 20th, 2023
57
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-20 16:06:33
  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. Display hours, minutes and seconds on 6x 7seg LED display. When mins and secs are 00 00, contact closure for about 1 sec. */
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  33. const uint8_t contactClosure_PIN_D7 = 7;
  34.  
  35. /***** DEFINITION OF SoftwareSerial *****/
  36. const uint8_t NEO_6M_GPS_module_PIN_SERIAL_TX_A0 = A0;
  37. const uint8_t NEO_6M_GPS_module_PIN_SERIAL_RX_A1 = A1;
  38. SoftwareSerial NEO_6M_GPS_module(NEO_6M_GPS_module_PIN_SERIAL_RX_A1, NEO_6M_GPS_module_PIN_SERIAL_TX_A0);
  39.  
  40. /***** DEFINITION OF I2C PINS *****/
  41. const uint8_t lcd_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  42.  
  43. /****** DEFINITION OF CLASS INSTANCES *****/
  44. MicroNMEA nmea; // MicroNMEA class instance
  45. LiquidCrystal_I2C lcd(lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // LiquidCrystal_I2C class instance
  46.  
  47. void setup(void)
  48. {
  49.   // Initialize contact closure pin as output
  50.   pinMode(contactClosure_PIN_D7, OUTPUT);
  51.  
  52.   // Initialize software serial for GPS module
  53.   NEO_6M_GPS_module.begin(9600);
  54.  
  55.   // Initialize LCD display
  56.   lcd.begin(16, 2);
  57.   lcd.backlight();
  58.  
  59.   // Clear LCD display
  60.   lcd.clear();
  61. }
  62.  
  63. void loop(void)
  64. {
  65.   // Read GPS data if available
  66.   while (NEO_6M_GPS_module.available())
  67.   {
  68.     char c = NEO_6M_GPS_module.read();
  69.     nmea.process(c);
  70.   }
  71.  
  72.   // Check for a valid GPS fix
  73.   if (nmea.isValid())
  74.   {
  75.     // Get hours, minutes, and seconds from GPS
  76.     int hours = nmea.getHour();
  77.     int minutes = nmea.getMinute();
  78.     int seconds = nmea.getSecond();
  79.  
  80.     // Display hours, minutes, and seconds on LCD
  81.     lcd.setCursor(0, 0);
  82.     lcd.print("Time: ");
  83.     lcd.print(hours);
  84.     lcd.print(":");
  85.     if (minutes < 10)
  86.     {
  87.       lcd.print("0");
  88.     }
  89.     lcd.print(minutes);
  90.     lcd.print(":");
  91.     if (seconds < 10)
  92.     {
  93.       lcd.print("0");
  94.     }
  95.     lcd.print(seconds);
  96.  
  97.     // Check if minutes and seconds are zero
  98.     if (minutes == 0 && seconds == 0)
  99.     {
  100.       // Activate contact closure for 1 second
  101.       digitalWrite(contactClosure_PIN_D7, HIGH);
  102.       delay(1000);
  103.       digitalWrite(contactClosure_PIN_D7, LOW);
  104.     }
  105.   }
  106.   else
  107.   {
  108.     // Display "No Fix" message on LCD
  109.     lcd.setCursor(0, 0);
  110.     lcd.print("No Fix");
  111.   }
  112. }
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement