Advertisement
pleasedontcode

Scanner rev_79

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