Advertisement
pleasedontcode

Scanner rev_35

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