Advertisement
pleasedontcode

Scanner rev_68

Nov 1st, 2023
64
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-11-01 17:50:08
  15.     - Source Code generated by: AlexWind
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <SoftwareSerial.h>
  21. #include <Wire.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 LED */
  28. /* 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 readGPSData(void);
  35. void displayTimeOnLCD(uint8_t hours, uint8_t minutes, uint8_t seconds);
  36. void performContactClosure(void);
  37.  
  38. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  39. const uint8_t enabler_PushButton_PIN_D3 = 3;
  40.  
  41. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  42. const uint8_t contactClosure_PIN_D2 = 2;
  43.  
  44. /***** DEFINITION OF Software Serial *****/
  45. const uint8_t gpsSerial_PIN_SERIAL_TX_A1 = A1;
  46. const uint8_t gpsSerial_PIN_SERIAL_RX_A0 = A0;
  47. SoftwareSerial gpsSerial(gpsSerial_PIN_SERIAL_RX_A0, gpsSerial_PIN_SERIAL_TX_A1);
  48.  
  49. /***** DEFINITION OF I2C PINS *****/
  50. const uint8_t led_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  51. const uint8_t led_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  52. const uint8_t led_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  53.  
  54. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  55. LiquidCrystal_I2C lcd(led_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // Instantiate the LCD object
  56. char nmeaBuffer[100];
  57. MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer)); // Instantiate the MicroNMEA object
  58.  
  59. void setup(void)
  60. {
  61.   // put your setup code here, to run once:
  62.  
  63.   pinMode(enabler_PushButton_PIN_D3, INPUT_PULLUP);
  64.  
  65.   pinMode(contactClosure_PIN_D2, OUTPUT);
  66.  
  67.   gpsSerial.begin(9600);
  68.  
  69.   lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
  70.   lcd.backlight(); // Turn on the backlight
  71.  
  72.   lcd.setCursor(0, 0); // Set the cursor to the first column of the first row
  73.   lcd.print("Hello, World!"); // Print a message on the LCD
  74. }
  75.  
  76. void loop(void)
  77. {
  78.   // put your main code here, to run repeatedly:
  79.   readGPSData();
  80. }
  81.  
  82. void readGPSData(void)
  83. {
  84.   while (gpsSerial.available())
  85.   {
  86.     char c = gpsSerial.read();
  87.     nmea.process(c);
  88.   }
  89.  
  90.   if (nmea.isValid())
  91.   {
  92.     uint8_t hours = nmea.getHour();
  93.     uint8_t minutes = nmea.getMinute();
  94.     uint8_t seconds = nmea.getSecond();
  95.  
  96.     displayTimeOnLCD(hours, minutes, seconds);
  97.  
  98.     if (minutes == 0 && seconds == 0)
  99.     {
  100.       performContactClosure();
  101.     }
  102.   }
  103. }
  104.  
  105. void displayTimeOnLCD(uint8_t hours, uint8_t minutes, uint8_t seconds)
  106. {
  107.   lcd.clear();
  108.   lcd.setCursor(0, 0);
  109.   lcd.print("Time: ");
  110.   lcd.print(hours);
  111.   lcd.print(":");
  112.   if (minutes < 10)
  113.   {
  114.     lcd.print("0");
  115.   }
  116.   lcd.print(minutes);
  117.   lcd.print(":");
  118.   if (seconds < 10)
  119.   {
  120.     lcd.print("0");
  121.   }
  122.   lcd.print(seconds);
  123. }
  124.  
  125. void performContactClosure(void)
  126. {
  127.   digitalWrite(contactClosure_PIN_D2, HIGH);
  128.   delay(1000);
  129.   digitalWrite(contactClosure_PIN_D2, LOW);
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement