Advertisement
pleasedontcode

Button Counter rev_01

Dec 18th, 2023
83
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: Button Counter
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2023-12-18 08:58:18
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* ++++++++++++++++++++++++++++++++++++++++++++++++++ */
  21.     /* ++++++++++++++++++++++++++++++++++++++++++++++++++ */
  22.     /* ++++++++++++++++++++++++++++++++++++++++++++++++++ */
  23.     /* ++++++++++++++++++++++++++++++++++++++++++++++++++ */
  24.     /* ++++++++++++++++++++++++++++++++++++++++++++++++++ */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Arduino.h>
  29. #include <EasyButton.h>
  30.  
  31. /****** SYSTEM REQUIREMENTS *****/
  32. /****** SYSTEM REQUIREMENT 1 *****/
  33. /* ++++++++++++++++++++++++++++++++++++++++++++++++++ */
  34. /* +++++++++++++++ Button Press Counter ++++++++++++++ */
  35. /* ++++++++++++++++++++++++++++++++++++++++++++++++++ */
  36. int buttonPressCount = 0;
  37.  
  38. /****** FUNCTION PROTOTYPES *****/
  39. void setup(void);
  40. void loop(void);
  41.  
  42. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  43. const uint8_t BUTTON_PIN = 2;
  44.  
  45. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  46. EasyButton button(BUTTON_PIN); // Initialize EasyButton object
  47.  
  48. void setup(void)
  49. {
  50.   // put your setup code here, to run once:
  51.   pinMode(BUTTON_PIN, INPUT_PULLUP);
  52.  
  53.   button.begin(); // Begin EasyButton
  54. }
  55.  
  56. void loop(void)
  57. {
  58.   // put your main code here, to run repeatedly:
  59.   button.read(); // Read button state
  60.  
  61.   // Check if button is pressed
  62.   if (button.isPressed())
  63.   {
  64.     // Increment button press counter
  65.     buttonPressCount++;
  66.  
  67.     // Print button press count
  68.     Serial.print("Button pressed. Press count: ");
  69.     Serial.println(buttonPressCount);
  70.   }
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement