Advertisement
pleasedontcode

"Button Handling" rev_05

Jun 26th, 2024
730
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 Handling"
  13.     - Source Code compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-06-26 20:00:08
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement a push-button control system using */
  21.     /* EasyButton library to detect button presses on */
  22.     /* digital pin D2. The system should initialize the */
  23.     /* button in setup() and continuously check for */
  24.     /* button state changes in loop(). */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <EasyButton.h>  //https://github.com/evert-arias/EasyButton
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t butt_PushButton_PIN_D2 = 2;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. EasyButton button(butt_PushButton_PIN_D2); // Initialize EasyButton object with the pin number
  40.  
  41. /****** FUNCTION DECLARATIONS *****/
  42. void onPressed(); // Function to handle button press event
  43.  
  44. void setup(void)
  45. {
  46.   // Initialize serial communication at 115200 baud rate
  47.   Serial.begin(115200);
  48.   Serial.println();
  49.   Serial.println(">>> EasyButton pressed example <<<");
  50.  
  51.   // Initialize the button
  52.   button.begin();
  53.   // Attach the onPressed function to the button press event
  54.   button.onPressed(onPressed);
  55. }
  56.  
  57. void loop(void)
  58. {
  59.   // Continuously read the button state
  60.   button.read();
  61. }
  62.  
  63. void onPressed()
  64. {
  65.   // Print message when button is pressed
  66.   Serial.println("Button pressed");
  67. }
  68.  
  69. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement