Advertisement
pleasedontcode

Button Detection rev_01

Sep 18th, 2024
111
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-18 14:40:00
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop a responsive button control system */
  21.     /* utilizing the EasyButton library, focusing on */
  22.     /* digital pin D2 for input. The design should */
  23.     /* prioritize debouncing and state management for */
  24.     /* effective user interaction. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t rf_PushButton_PIN_D2 = 2;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. // Initialize the EasyButton object with the defined pin
  39. EasyButton button(rf_PushButton_PIN_D2);
  40.  
  41. /****** FUNCTION DEFINITIONS *****/
  42. // Function to be called when the button is pressed
  43. void onPressed()
  44. {
  45.     Serial.println("Button pressed"); // Print message when button is pressed
  46. }
  47.  
  48. void setup(void)
  49. {
  50.     // Start serial communication for debugging
  51.     Serial.begin(115200);
  52.     Serial.println();
  53.     Serial.println(">>> EasyButton pressed example <<<");
  54.  
  55.     // Initialize the button
  56.     button.begin();
  57.     // Register the onPressed function to be called when the button is pressed
  58.     button.onPressed(onPressed);
  59.  
  60.     // Set the push button pin as INPUT_PULLUP
  61.     pinMode(rf_PushButton_PIN_D2, INPUT_PULLUP); // Ensure the pin is set to INPUT_PULLUP for debouncing
  62. }
  63.  
  64. void loop(void)
  65. {
  66.     // Continuously read the button state
  67.     button.read(); // Read the button state to manage debouncing and state
  68. }
  69.  
  70. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement