Advertisement
pleasedontcode

Scanner rev_69

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 17:52:53
  15.     - Source Code generated by: AlexWind
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /********* User code review feedback **********
  20. #### Feedback 1 ####
  21. - transform code using display with seven segments.
  22. ********* User code review feedback **********/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26. #include <SoftwareSerial.h>
  27. #include <Wire.h>
  28. #include <LiquidCrystal_I2C.h>
  29. #include <MicroNMEA.h>
  30. #include <SevSeg.h> // Include the Seven Segment Display library
  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 readGPSData(void);
  42. void displayTimeOnSevenSegment(uint8_t hours, uint8_t minutes, uint8_t seconds); // Updated function name
  43. void performContactClosure(void);
  44.  
  45. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  46. const uint8_t enabler_PushButton_PIN_D3 = 3;
  47.  
  48. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  49. const uint8_t contactClosure_PIN_D2 = 2;
  50.  
  51. /***** DEFINITION OF Software Serial *****/
  52. const uint8_t gpsSerial_PIN_SERIAL_TX_A1 = A1;
  53. const uint8_t gpsSerial_PIN_SERIAL_RX_A0 = A0;
  54. SoftwareSerial gpsSerial(gpsSerial_PIN_SERIAL_RX_A0, gpsSerial_PIN_SERIAL_TX_A1);
  55.  
  56. /***** DEFINITION OF I2C PINS *****/
  57. const uint8_t led_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  58. const uint8_t led_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  59. const uint8_t led_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  60.  
  61. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  62. LiquidCrystal_I2C lcd(led_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // Instantiate the LCD object
  63. char nmeaBuffer[100];
  64. MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer)); // Instantiate the MicroNMEA object
  65. SevSeg sevseg; // Instantiate the Seven Segment Display 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.   lcd.setCursor(0, 0); // Set the cursor to the first column of the first row
  81.   lcd.print("Hello, World!"); // Print a message on the LCD
  82.  
  83.   sevseg.begin(COMMON_CATHODE, 4, 3, 2, 1, 0, 6, 7); // Initialize the Seven Segment Display with 8 arguments
  84.   sevseg.setBrightness(90); // Set the brightness of the display (0-100)
  85. }
  86.  
  87. void loop(void)
  88. {
  89.   // put your main code here, to run repeatedly:
  90.   readGPSData();
  91. }
  92.  
  93. void readGPSData(void)
  94. {
  95.   while (gpsSerial.available())
  96.   {
  97.     char c = gpsSerial.read();
  98.     nmea.process(c);
  99.   }
  100.  
  101.   if (nmea.isValid())
  102.   {
  103.     uint8_t hours = nmea.getHour();
  104.     uint8_t minutes = nmea.getMinute();
  105.     uint8_t seconds = nmea.getSecond();
  106.  
  107.     displayTimeOnSevenSegment(hours, minutes, seconds); // Updated function name
  108.  
  109.     if (minutes == 0 && seconds == 0)
  110.     {
  111.       performContactClosure();
  112.     }
  113.   }
  114. }
  115.  
  116. void displayTimeOnSevenSegment(uint8_t hours, uint8_t minutes, uint8_t seconds) // Updated function name
  117. {
  118.   sevseg.setNumber(hours * 100 + minutes); // Set the number to be displayed on the Seven Segment Display
  119.   sevseg.refreshDisplay(); // Refresh the display
  120.  
  121.   if (minutes == 0 && seconds == 0)
  122.   {
  123.     sevseg.setNumber(0); // Set the number to 0 to turn off the display
  124.     sevseg.refreshDisplay(); // Refresh the display
  125.   }
  126. }
  127.  
  128. void performContactClosure(void)
  129. {
  130.   digitalWrite(contactClosure_PIN_D2, HIGH);
  131.   delay(1000);
  132.   digitalWrite(contactClosure_PIN_D2, LOW);
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement