Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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:03:17
- - Source Code generated by: AlexWind
- ********* Pleasedontcode.com **********/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <Wire.h>
- #include <EasyButton.h>
- #include <LiquidCrystal_I2C.h>
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Count display on lcd with push button press */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* counter upto 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
- int counter = 0;
- // LCD object
- LiquidCrystal_I2C lcd(Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2);
- // Button objects
- EasyButton pb2_PushButton(pb2_PushButton_PIN_D2);
- EasyButton myButton_PushButton(myButton_PushButton_PIN_D3);
- void setup(void)
- {
- // Initialize LCD
- lcd.begin(16, 2);
- lcd.print("Counter: ");
- lcd.setCursor(0, 1);
- lcd.print(counter);
- // Initialize buttons
- pb2_PushButton.begin();
- myButton_PushButton.begin();
- // Set LED pin as output
- pinMode(l1_LED_PIN_D4, OUTPUT);
- }
- void loop(void)
- {
- // Update button states
- pb2_PushButton.read();
- myButton_PushButton.read();
- // Check if pb2_PushButton is pressed
- if (pb2_PushButton.wasPressed())
- {
- // Increment counter
- counter++;
- if (counter > 100000)
- {
- counter = 0;
- }
- // Update LCD display
- lcd.setCursor(8, 1);
- lcd.print(" ");
- lcd.setCursor(8, 1);
- lcd.print(counter);
- }
- // Check if myButton_PushButton is pressed
- if (myButton_PushButton.wasPressed())
- {
- // Toggle LED
- digitalWrite(l1_LED_PIN_D4, !digitalRead(l1_LED_PIN_D4));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement