Advertisement
pleasedontcode

Scanner rev_82

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