Advertisement
pleasedontcode

Counter Display rev_02

Mar 3rd, 2025
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Counter Display
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-03-03 15:04:23
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* allora quando io premo il pulsante collegato al */
  21.     /* pin 0 deve scrivere sul display il numero 0, */
  22.     /* continuando in su fino al pin nove che a sua volta */
  23.     /* dovra scrivere/stampare il numero 9 sul display */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /********* User code review feedback **********
  28. #### Feedback 1 ####
  29. - devi usare le librerie #include <Adafruit_LiquidCrystal.h>
  30. ********* User code review feedback **********/
  31.  
  32. /* START CODE */
  33.  
  34. /****** DEFINITION OF LIBRARIES *****/
  35. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  36. #include <Adafruit_LiquidCrystal.h> // Include the Adafruit LiquidCrystal library
  37.  
  38. /****** FUNCTION PROTOTYPES *****/
  39. void setup(void);
  40. void loop(void);
  41.  
  42. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  43. const uint8_t PushButton_PIN_D2 = 2; // Fixed naming convention
  44.  
  45. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  46. EasyButton button(PushButton_PIN_D2); // Create an instance of EasyButton
  47. Adafruit_LiquidCrystal lcd(0); // Create an instance of the Adafruit LiquidCrystal class with the appropriate parameters
  48.  
  49. int counter = 0; // Counter to keep track of button presses
  50.  
  51. void setup(void)
  52. {
  53.     // put your setup code here, to run once:
  54.     pinMode(PushButton_PIN_D2, INPUT_PULLUP); // Set the button pin as input with pull-up
  55.  
  56.     lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
  57.     lcd.print("Press the button"); // Initial message on the LCD
  58.  
  59.     button.begin(); // Initialize the button
  60.     button.onPressed(incrementCounter); // Set the function to call on button press
  61. }
  62.  
  63. void loop(void)
  64. {
  65.     // put your main code here, to run repeatedly:
  66.     button.read(); // Read the button state
  67. }
  68.  
  69. // Function to increment the counter and update the display
  70. void incrementCounter() {
  71.     if (counter < 9) {
  72.         counter++; // Increment the counter
  73.     } else {
  74.         counter = 0; // Reset the counter if it exceeds 9
  75.     }
  76.     lcd.clear(); // Clear the LCD
  77.     lcd.print(counter); // Display the current counter value
  78. }
  79.  
  80. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement