Advertisement
pleasedontcode

Scanner rev_78

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