Advertisement
pleasedontcode

Scanner rev_76

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