Advertisement
pleasedontcode

Button Detection rev_03

Jul 23rd, 2024
170
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 Mega
  14.     - Source Code created on: 2024-07-23 08:04:44
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* read button */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29.  
  30. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  31. const uint8_t button_PushButton_PIN_D2      = 2;
  32.  
  33. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  34. // Instance of the EasyButton class for the button connected to pin D2
  35. EasyButton button(button_PushButton_PIN_D2); // Correctly instantiate the EasyButton object
  36.  
  37. void setup(void)
  38. {
  39.     // Initialize Serial for debugging purposes
  40.     Serial.begin(115200);
  41.     Serial.println();
  42.     Serial.println(">>> EasyButton pressed example <<<");
  43.  
  44.     // Initialize the button
  45.     button.begin(); // Call the begin method to set up the button
  46.     // Add the callback function to be called when the button is pressed
  47.     button.onPressed([]() {
  48.         Serial.println("Button pressed"); // Print message when button is pressed
  49.     });
  50. }
  51.  
  52. void loop(void)
  53. {
  54.     // Continuously read the status of the button
  55.     button.read(); // Call read method to update button state
  56. }
  57.  
  58. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement