Advertisement
pleasedontcode

Scanner rev_77

Nov 1st, 2023
82
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:23:33
  15.     - Source Code generated by: AlexWind
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /********* User code review feedback **********
  20. #### Feedback 1 ####
  21. - review displayTime because the reset of minutes, and seconds is
  22. 10; instead they should be 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 displayTime(uint8_t hours, uint8_t minutes, uint8_t seconds);
  42. void triggerContactClosure();
  43.  
  44. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  45. const uint8_t enabler_PushButton_PIN_D3 = 3;
  46.  
  47. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  48. const uint8_t contactClosure_PIN_D2 = 2;
  49.  
  50. /***** DEFINITION OF Software Serial *****/
  51. const uint8_t gpsSerial_PIN_SERIAL_TX_A1 = A1;
  52. const uint8_t gpsSerial_PIN_SERIAL_RX_A0 = A0;
  53. SoftwareSerial gpsSerial(gpsSerial_PIN_SERIAL_RX_A0, gpsSerial_PIN_SERIAL_TX_A1);
  54.  
  55. /***** DEFINITION OF I2C PINS *****/
  56. const uint8_t led_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  57. const uint8_t led_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  58. const uint8_t led_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  59.  
  60. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  61. LiquidCrystal_I2C lcd(led_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // Initialize the LiquidCrystal_I2C object
  62. char nmeaBuffer[100];
  63. MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer)); // Initialize the MicroNMEA object
  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 with 16 columns and 2 rows
  76.   lcd.backlight(); // Turn on the backlight
  77. }
  78.  
  79. void loop(void)
  80. {
  81.   // put your main code here, to run repeatedly:
  82.   while (gpsSerial.available())
  83.   {
  84.     char c = gpsSerial.read();
  85.     nmea.process(c);
  86.   }
  87.  
  88.   if (nmea.isValid())
  89.   {
  90.     uint8_t hours = nmea.getHour();
  91.     uint8_t minutes = nmea.getMinute();
  92.     uint8_t seconds = nmea.getSecond();
  93.  
  94.     displayTime(hours, minutes, seconds);
  95.  
  96.     if (minutes == 0 && seconds == 0)
  97.     {
  98.       triggerContactClosure();
  99.     }
  100.   }
  101. }
  102.  
  103. void displayTime(uint8_t hours, uint8_t minutes, uint8_t seconds)
  104. {
  105.   lcd.setCursor(0, 0);
  106.   lcd.print("Time: ");
  107.   lcd.print(hours);
  108.   lcd.print(":");
  109.   if (minutes < 10)
  110.   {
  111.     lcd.print("0");
  112.   }
  113.   lcd.print(minutes);
  114.   lcd.print(":");
  115.   if (seconds < 10)
  116.   {
  117.     lcd.print("0");
  118.   }
  119.   lcd.print(seconds);
  120. }
  121.  
  122. void triggerContactClosure()
  123. {
  124.   digitalWrite(contactClosure_PIN_D2, HIGH);
  125.   delay(1000);
  126.   digitalWrite(contactClosure_PIN_D2, LOW);
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement