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: **Button Counter**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-03-03 15:01:43
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* allora quando io premo il pulsante collegato al */
- /* pin 0 deve scrivere sul display il numero 0, */
- /* continuando in su fino al pin nove che a sua volta */
- /* dovra scrivere/stampare il numero 9 sul display */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- #include <LCD-SOLDERED.h> //https://github.com/SolderedElectronics/Soldered-LCD-library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t PushButton_PIN_D2 = 2; // Fixed naming convention
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- EasyButton button(PushButton_PIN_D2); // Create an instance of EasyButton
- LCD lcd; // Create an instance of the LCD class
- int counter = 0; // Counter to keep track of button presses
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(PushButton_PIN_D2, INPUT_PULLUP); // Set the button pin as input with pull-up
- lcd.begin(); // Initialize the LCD
- lcd.print("Press the button"); // Initial message on the LCD
- button.begin(); // Initialize the button
- button.onPressed(incrementCounter); // Set the function to call on button press
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- button.read(); // Read the button state
- }
- // Function to increment the counter and update the display
- void incrementCounter() {
- if (counter < 9) {
- counter++; // Increment the counter
- } else {
- counter = 0; // Reset the counter if it exceeds 9
- }
- lcd.clear(); // Clear the LCD
- lcd.print(counter); // Display the current counter value
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement