Advertisement
pleasedontcode

"Button Callback" rev_01

Jul 7th, 2024
288
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 Callback"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-07-07 22:32:13
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement a system to detect button presses using */
  21.     /* the EasyButton library. The system should */
  22.     /* initialize a push button connected to pin D2 and */
  23.     /* continuously monitor its state, triggering */
  24.     /* specific actions upon button press events. */
  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. void onPressed(void); // Callback function prototype
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t left_PushButton_PIN_D2 = 2;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. EasyButton button(left_PushButton_PIN_D2); // Initialize EasyButton object
  40.  
  41. void onPressed()
  42. {
  43.   Serial.println("Button pressed"); // Callback function definition
  44. }
  45.  
  46. void setup(void)
  47. {
  48.   // put your setup code here, to run once:
  49.   Serial.begin(115200); // Initialize Serial for debugging
  50.   Serial.println();
  51.   Serial.println(">>> EasyButton pressed example <<<");
  52.  
  53.   button.begin(); // Initialize the button
  54.   button.onPressed(onPressed); // Set the callback function for button press
  55. }
  56.  
  57. void loop(void)
  58. {
  59.   // put your main code here, to run repeatedly:
  60.   button.read(); // Continuously read the status of the button
  61. }
  62.  
  63. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement