Advertisement
pleasedontcode

GPSTime rev_115

Nov 20th, 2023
68
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:23:35
  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. const uint8_t contactClosure_PIN_D7 = 7;
  26. const uint8_t NEO_6M_GPS_module_PIN_SERIAL_TX_A0 = A0;
  27. const uint8_t NEO_6M_GPS_module_PIN_SERIAL_RX_A1 = A1;
  28.  
  29. SoftwareSerial NEO_6M_GPS_module(NEO_6M_GPS_module_PIN_SERIAL_RX_A1, NEO_6M_GPS_module_PIN_SERIAL_TX_A0);
  30. LiquidCrystal_I2C lcd(0x27, 16, 2);
  31. MicroNMEA nmea;
  32.  
  33. void setup(void)
  34. {
  35.   pinMode(contactClosure_PIN_D7, OUTPUT);
  36.   NEO_6M_GPS_module.begin(9600);
  37.   lcd.begin(16, 2);
  38.   lcd.setCursor(0, 0);
  39.   lcd.print("Initializing...");
  40.   delay(2000);
  41.   lcd.clear();
  42.   lcd.setCursor(0, 0);
  43.   lcd.print("GPS Module Ready");
  44. }
  45.  
  46. void loop(void)
  47. {
  48.   if (NEO_6M_GPS_module.available())
  49.   {
  50.     readGPSData();
  51.     displayTimeOnLCD();
  52.   }
  53. }
  54.  
  55. void readGPSData(void)
  56. {
  57.   while (NEO_6M_GPS_module.available())
  58.   {
  59.     char c = NEO_6M_GPS_module.read();
  60.     nmea.process(c);
  61.   }
  62. }
  63.  
  64. void displayTimeOnLCD(void)
  65. {
  66.   if (nmea.isValid() && nmea.getHour() && nmea.getMinute() && nmea.getSecond())
  67.   {
  68.     lcd.clear();
  69.     lcd.setCursor(0, 0);
  70.     lcd.print("Time: ");
  71.     lcd.print(nmea.getHour());
  72.     lcd.print(":");
  73.     lcd.print(nmea.getMinute());
  74.     lcd.print(":");
  75.     lcd.print(nmea.getSecond());
  76.  
  77.     if (nmea.getHour() == 0 && nmea.getMinute() == 0 && nmea.getSecond() == 0)
  78.     {
  79.       digitalWrite(contactClosure_PIN_D7, HIGH);
  80.       delay(1000);
  81.       digitalWrite(contactClosure_PIN_D7, LOW);
  82.     }
  83.   }
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement