Advertisement
pleasedontcode

Scanner rev_81

Nov 1st, 2023
81
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 19:40:14
  15.     - Source Code generated by: AlexWind
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /********* User code review feedback **********
  20. #### Feedback 1 ####
  21. - why do you reset seconds and minutes to 10? Don't they should be
  22.  60?
  23. ********* User code review feedback **********/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Arduino.h>
  27. #include <SoftwareSerial.h>
  28. #include <Wire.h>
  29. #include <LiquidCrystal_I2C.h>
  30. #include <MicroNMEA.h>
  31.  
  32. /****** SYSTEM REQUIREMENT 1 *****/
  33. /* Reads NMEA 8bit data from GPS module. Reads hours */
  34. /* minutes, seconds and Display h, m, s on LED */
  35. /* display. When mins and secs are 00 00, contact */
  36. /* closure for about 1 sec. */
  37.  
  38. /****** FUNCTION PROTOTYPES *****/
  39. void setup(void);
  40. void loop(void);
  41. void readGPSData(void);
  42. void displayTimeOnLCD(uint8_t hours, uint8_t minutes, uint8_t seconds);
  43. void performContactClosure(void);
  44.  
  45. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  46. const uint8_t enabler_PushButton_PIN_D3 = 3;
  47.  
  48. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  49. const uint8_t contactClosure_PIN_D2 = 2;
  50.  
  51. /***** DEFINITION OF Software Serial *****/
  52. const uint8_t gpsSerial_PIN_SERIAL_TX_A1 = A1;
  53. const uint8_t gpsSerial_PIN_SERIAL_RX_A0 = A0;
  54. SoftwareSerial gpsSerial(gpsSerial_PIN_SERIAL_RX_A0, gpsSerial_PIN_SERIAL_TX_A1);
  55.  
  56. /***** DEFINITION OF I2C PINS *****/
  57. const uint8_t led_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  58. const uint8_t led_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  59. const uint8_t led_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  60.  
  61. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  62. LiquidCrystal_I2C lcd(led_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // Initialize the LiquidCrystal_I2C object
  63. MicroNMEA nmea;
  64.  
  65. void setup(void)
  66. {
  67.   // put your setup code here, to run once:
  68.  
  69.   pinMode(enabler_PushButton_PIN_D3, INPUT_PULLUP);
  70.  
  71.   pinMode(contactClosure_PIN_D2, OUTPUT);
  72.  
  73.   gpsSerial.begin(9600);
  74.  
  75.   lcd.begin(16, 2); // Initialize the LCD display
  76.  
  77.   lcd.backlight(); // Turn on the backlight
  78.  
  79.   lcd.clear(); // Clear the LCD display
  80.  
  81.   lcd.setCursor(0, 0); // Set the cursor to the first column of the first row
  82.   lcd.print("Hello, Arduino!"); // Print a message on the LCD display
  83. }
  84.  
  85. void loop(void)
  86. {
  87.   // put your main code here, to run repeatedly:
  88.   readGPSData();
  89. }
  90.  
  91. void readGPSData(void)
  92. {
  93.   while (gpsSerial.available())
  94.   {
  95.     char c = gpsSerial.read();
  96.     nmea.process(c);
  97.   }
  98.  
  99.   if (nmea.isValid())
  100.   {
  101.     uint8_t hours = nmea.getHour();
  102.     uint8_t minutes = nmea.getMinute();
  103.     uint8_t seconds = nmea.getSecond();
  104.  
  105.     displayTimeOnLCD(hours, minutes, seconds);
  106.  
  107.     if (minutes == 0 && seconds == 0)
  108.     {
  109.       performContactClosure();
  110.     }
  111.   }
  112. }
  113.  
  114. void displayTimeOnLCD(uint8_t hours, uint8_t minutes, uint8_t seconds)
  115. {
  116.   lcd.clear();
  117.   lcd.setCursor(0, 0);
  118.   lcd.print("Time: ");
  119.   lcd.print(hours);
  120.   lcd.print(":");
  121.   if (minutes < 10)
  122.   {
  123.     lcd.print("0");
  124.   }
  125.   lcd.print(minutes);
  126.   lcd.print(":");
  127.   if (seconds < 10)
  128.   {
  129.     lcd.print("0");
  130.   }
  131.   lcd.print(seconds);
  132. }
  133.  
  134. void performContactClosure(void)
  135. {
  136.   digitalWrite(contactClosure_PIN_D2, HIGH);
  137.   delay(1000);
  138.   digitalWrite(contactClosure_PIN_D2, LOW);
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement