Advertisement
pleasedontcode

"EasyButton Integration" rev_04

Jun 24th, 2024
448
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: "EasyButton Integration"
  13.     - Source Code NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-06-24 14:22:42
  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. /****** 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 butt_PushButton_PIN_D2 = 2;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. EasyButton button(butt_PushButton_PIN_D2); // Initialize EasyButton object with the pin number
  39.  
  40. /****** FUNCTION DECLARATIONS *****/
  41. void onPressed(); // Function to handle button press event
  42.  
  43. void setup(void)
  44. {
  45.   // Initialize serial communication at 115200 baud rate
  46.   Serial.begin(115200);
  47.   Serial.println();
  48.   Serial.println(">>> EasyButton pressed example <<<");
  49.  
  50.   // Initialize the button
  51.   button.begin();
  52.   // Attach the onPressed function to the button press event
  53.   button.onPressed(onPressed);
  54. }
  55.  
  56. void loop(void)
  57. {
  58.   // Continuously read the button state
  59.   button.read();
  60. }
  61.  
  62. void onPressed()
  63. {
  64.   // Print message when button is pressed
  65.   Serial.println("Button pressed");
  66. }
  67.  
  68. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement