/********* 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 21:05:12
- Source Code generated by: AlexWind
********* Pleasedontcode.com **********/
/****** 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);
void updateCounter(int count);
/***** 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 = 0x27; // Change the address if necessary
// Global variables
int counter = 0;
LiquidCrystal_I2C lcd(Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // Initialize LCD object
EasyButton pb2(pb2_PushButton_PIN_D2); // Initialize EasyButton object for pb2
EasyButton myButton(myButton_PushButton_PIN_D3); // Initialize EasyButton object for myButton
void setup(void)
{
// Initialize LCD
lcd.begin(16, 2);
lcd.print("Counter: ");
lcd.setCursor(0, 1);
lcd.print(counter);
// Initialize buttons
pb2.begin();
myButton.begin();
// Set LED pin as output
pinMode(l1_LED_PIN_D4, OUTPUT);
}
void loop(void)
{
// Update buttons
pb2.read();
myButton.read();
// Check if pb2 button is pressed
if (pb2.wasPressed())
{
counter++;
updateCounter(counter);
}
// Check if myButton button is pressed
if (myButton.wasPressed())
{
counter = 0;
updateCounter(counter);
}
}
void updateCounter(int count)
{
lcd.setCursor(9, 1);
lcd.print(" "); // Clear previous counter value
lcd.setCursor(9, 1);
lcd.print(count);
}