CCCPaste

Scanner rev_69

/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: Scanner
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2023-11-01 17:52:53
	- Source Code generated by: AlexWind

********* Pleasedontcode.com **********/

/********* User code review feedback **********
#### Feedback 1 ####
- transform code using display with seven segments.
********* User code review feedback **********/

/****** DEFINITION OF LIBRARIES *****/
#include 
#include 
#include 
#include 
#include 
#include  // Include the Seven Segment Display library

/****** SYSTEM REQUIREMENT 1 *****/
/* Reads NMEA 8bit data from GPS module . Reads hours */
/* minutes, seconds and Display h, m, s on LED */
/* display. When mins and secs are 00 00, contact */
/* closure for about 1 sec. */

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void readGPSData(void);
void displayTimeOnSevenSegment(uint8_t hours, uint8_t minutes, uint8_t seconds); // Updated function name
void performContactClosure(void);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t enabler_PushButton_PIN_D3 = 3;

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t contactClosure_PIN_D2 = 2;

/***** DEFINITION OF Software Serial *****/
const uint8_t gpsSerial_PIN_SERIAL_TX_A1 = A1;
const uint8_t gpsSerial_PIN_SERIAL_RX_A0 = A0;
SoftwareSerial gpsSerial(gpsSerial_PIN_SERIAL_RX_A0, gpsSerial_PIN_SERIAL_TX_A1);

/***** DEFINITION OF I2C PINS *****/
const uint8_t led_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
const uint8_t led_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
const uint8_t led_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
LiquidCrystal_I2C lcd(led_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // Instantiate the LCD object
char nmeaBuffer[100];
MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer)); // Instantiate the MicroNMEA object
SevSeg sevseg; // Instantiate the Seven Segment Display object

void setup(void)
{
  // put your setup code here, to run once:

  pinMode(enabler_PushButton_PIN_D3, INPUT_PULLUP);

  pinMode(contactClosure_PIN_D2, OUTPUT);

  gpsSerial.begin(9600);

  lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
  lcd.backlight(); // Turn on the backlight

  lcd.setCursor(0, 0); // Set the cursor to the first column of the first row
  lcd.print("Hello, World!"); // Print a message on the LCD

  sevseg.begin(COMMON_CATHODE, 4, 3, 2, 1, 0, 6, 7); // Initialize the Seven Segment Display with 8 arguments
  sevseg.setBrightness(90); // Set the brightness of the display (0-100)
}

void loop(void)
{
  // put your main code here, to run repeatedly:
  readGPSData();
}

void readGPSData(void)
{
  while (gpsSerial.available())
  {
    char c = gpsSerial.read();
    nmea.process(c);
  }

  if (nmea.isValid())
  {
    uint8_t hours = nmea.getHour();
    uint8_t minutes = nmea.getMinute();
    uint8_t seconds = nmea.getSecond();

    displayTimeOnSevenSegment(hours, minutes, seconds); // Updated function name

    if (minutes == 0 && seconds == 0)
    {
      performContactClosure();
    }
  }
}

void displayTimeOnSevenSegment(uint8_t hours, uint8_t minutes, uint8_t seconds) // Updated function name
{
  sevseg.setNumber(hours * 100 + minutes); // Set the number to be displayed on the Seven Segment Display
  sevseg.refreshDisplay(); // Refresh the display

  if (minutes == 0 && seconds == 0)
  {
    sevseg.setNumber(0); // Set the number to 0 to turn off the display
    sevseg.refreshDisplay(); // Refresh the display
  }
}

void performContactClosure(void)
{
  digitalWrite(contactClosure_PIN_D2, HIGH);
  delay(1000);
  digitalWrite(contactClosure_PIN_D2, LOW);
}