Advertisement
pleasedontcode

Button Detection rev_01

Oct 9th, 2024
317
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-10-09 17:08:59
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement a button-controlled mechanism using the */
  21.     /* EasyButton library, ensuring reliable input */
  22.     /* handling for the push button connected to digital */
  23.     /* pin D2. The system should respond to button */
  24.     /* presses with appropriate feedback. */
  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 BUTTON_PIN = 2; // Define the button pin for clarity
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. EasyButton button(BUTTON_PIN); // Instantiate the EasyButton object with the button pin
  39.  
  40. void onPressed() {
  41.     Serial.println("Button pressed"); // Callback function for button press
  42. }
  43.  
  44. void setup(void) {
  45.     Serial.begin(115200); // Initialize serial communication at 115200 baud rate
  46.     Serial.println();
  47.     Serial.println(">>> EasyButton pressed example <<<");
  48.  
  49.     // Set the button pin as input with pull-up resistor
  50.     button.begin(); // Initialize the EasyButton instance
  51.     button.onPressed(onPressed); // Attach the onPressed callback function
  52. }
  53.  
  54. void loop(void) {
  55.     button.read(); // Continuously read the button state
  56. }
  57.  
  58. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement