Advertisement
pleasedontcode

Scanner rev_34

Oct 29th, 2023
51
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: Scanner
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-10-29 13:59:10
  15.     - Source Code generated by: AlexWind
  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, contact */
  29. /* 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 performContactClosure();
  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. void setup(void)
  51. {
  52.   // Initialize contact closure pin
  53.   pinMode(contactClosure_PIN_D2, OUTPUT);
  54.  
  55.   // Initialize GPS serial communication
  56.   gpsSerial.begin(9600);
  57.  
  58.   // Initialize LCD display
  59.   LiquidCrystal_I2C lcd(display_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2);
  60.   lcd.begin(16, 2);
  61.   lcd.backlight();
  62. }
  63.  
  64. void loop(void)
  65. {
  66.   // Read GPS data
  67.   if (gpsSerial.available())
  68.   {
  69.     String nmeaSentence = gpsSerial.readStringUntil('\n');
  70.     if (nmeaSentence.startsWith("$GPRMC"))
  71.     {
  72.       MicroNMEA nmea;
  73.       nmea.process(nmeaSentence[0]); // Convert String to char
  74.  
  75.       // Check if the fix is valid
  76.       if (nmea.isValid())
  77.       {
  78.         // Get the time components
  79.         uint8_t hours = nmea.getHour();
  80.         uint8_t minutes = nmea.getMinute();
  81.         uint8_t seconds = nmea.getSecond();
  82.  
  83.         // Display the time on the LCD
  84.         displayTime(hours, minutes, seconds);
  85.  
  86.         // Check if minutes and seconds are both 00
  87.         if (minutes == 0 && seconds == 0)
  88.         {
  89.           performContactClosure();
  90.         }
  91.       }
  92.     }
  93.   }
  94. }
  95.  
  96. void displayTime(uint8_t hours, uint8_t minutes, uint8_t seconds)
  97. {
  98.   // Display the time on the LCD
  99.   LiquidCrystal_I2C lcd(display_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2);
  100.   lcd.clear();
  101.   lcd.setCursor(0, 0);
  102.   lcd.print("Time: ");
  103.   lcd.print(hours);
  104.   lcd.print(":");
  105.   if (minutes < 10)
  106.   {
  107.     lcd.print("0");
  108.   }
  109.   lcd.print(minutes);
  110.   lcd.print(":");
  111.   if (seconds < 10)
  112.   {
  113.     lcd.print("0");
  114.   }
  115.   lcd.print(seconds);
  116. }
  117.  
  118. void performContactClosure()
  119. {
  120.   // Perform contact closure for about 1 second
  121.   digitalWrite(contactClosure_PIN_D2, HIGH);
  122.   delay(1000);
  123.   digitalWrite(contactClosure_PIN_D2, LOW);
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement