/********* 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: Project02
- Source Code compiled for: Arduino Uno
- Source Code created on: 2023-10-14 20:53:36
- Source Code generated by: AlexWind
********* Pleasedontcode.com **********/
/********* User code review feedback **********
#### Feedback 1 ####
- complete coding of system requirements
********* User code review feedback **********/
/****** DEFINITION OF LIBRARIES *****/
#include
#include
#include
#include
/****** SYSTEM REQUIREMENT 1 *****/
// Count display on lcd with push button press
/****** SYSTEM REQUIREMENT 2 *****/
// Counter up to 100000
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t pb2_PushButton_PIN_D2 = 2;
const uint8_t myButton_PushButton_PIN_D3 = 3;
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t l1_LED_PIN_D4 = 4;
/***** DEFINITION OF I2C PINS *****/
const uint8_t Lcd_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
const uint8_t Lcd_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
const uint8_t Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
// Counter variable
unsigned int counter = 0;
// LCD object
LiquidCrystal_I2C lcd(Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, Lcd_LCD1602I2C_I2C_PIN_SDA_A4, Lcd_LCD1602I2C_I2C_PIN_SCL_A5);
void setup(void)
{
// put your setup code here, to run once:
pinMode(pb2_PushButton_PIN_D2, INPUT_PULLUP);
pinMode(myButton_PushButton_PIN_D3, INPUT_PULLUP);
pinMode(l1_LED_PIN_D4, OUTPUT);
lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
lcd.backlight(); // Turn on the LCD backlight
lcd.setCursor(0, 0); // Set the cursor to the first column of the first row
lcd.print("Counter:"); // Print the initial text on the LCD
}
void loop(void)
{
// put your main code here, to run repeatedly:
// Check if the push button is pressed
if (digitalRead(pb2_PushButton_PIN_D2) == LOW)
{
// Increment the counter
counter++;
// Check if the counter exceeds 100000
if (counter > 100000)
{
counter = 0; // Reset the counter if it exceeds 100000
}
// Update the LCD display with the new counter value
lcd.setCursor(8, 1); // Set the cursor to the ninth column of the second row
lcd.print(" "); // Clear the previous counter value
lcd.setCursor(8, 1); // Set the cursor to the ninth column of the second row
lcd.print(counter); // Print the new counter value
// Blink the LED to indicate button press
digitalWrite(l1_LED_PIN_D4, HIGH);
delay(100);
digitalWrite(l1_LED_PIN_D4, LOW);
delay(100);
}
}