Advertisement
pleasedontcode

Button Detection rev_01

Sep 21st, 2024
84
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 Detection
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-09-21 16:27:45
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement a push button interface using the */
  21.     /* EasyButton library, ensuring reliable button state */
  22.     /* detection with INPUT_PULLUP configuration on pin */
  23.     /* D2 for user interactions. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t gfg_PushButton_PIN_D2     = 2;
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. // Initialize the EasyButton object with the defined button pin
  38. EasyButton button(gfg_PushButton_PIN_D2); // Create an instance of EasyButton
  39.  
  40. // Function to be called when the button is pressed
  41. void onPressed()
  42. {
  43.     Serial.println("Button pressed"); // Print message to Serial Monitor
  44. }
  45.  
  46. void setup(void)
  47. {
  48.     // Start the Serial communication
  49.     Serial.begin(115200);
  50.     Serial.println();
  51.     Serial.println(">>> EasyButton pressed example <<<");
  52.  
  53.     // Set the button pin as input with pull-up resistor
  54.     pinMode(gfg_PushButton_PIN_D2, INPUT_PULLUP); // Configure pin D2 with INPUT_PULLUP
  55.  
  56.     // Initialize the EasyButton instance
  57.     button.begin();
  58.     // Attach the onPressed function to the button press event
  59.     button.onPressed(onPressed);
  60. }
  61.  
  62. void loop(void)
  63. {
  64.     // Read the button state
  65.     button.read(); // Check the button state and call the appropriate function
  66. }
  67.  
  68. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement