Advertisement
pleasedontcode

Button Detection rev_01

Aug 5th, 2024
124
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-08-05 16:26:36
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop a responsive LED chaser that changes modes */
  21.     /* with a button press. Use the EasyButton library */
  22.     /* for simplified button handling, ensuring the */
  23.     /* button on pin D2 is set to INPUT_PULLUP for */
  24.     /* optimal performance. */
  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 changemodebutton_PushButton_PIN_D2 = 2;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. // Initialize the EasyButton object for the button connected to pin D2
  39. EasyButton changemodebutton(changemodebutton_PushButton_PIN_D2);
  40.  
  41. /****** FUNCTION DEFINITIONS *****/
  42. void setup(void)
  43. {
  44.     // Initialize serial communication for debugging
  45.     Serial.begin(115200);
  46.    
  47.     // Set the button pin as INPUT_PULLUP for optimal performance
  48.     pinMode(changemodebutton_PushButton_PIN_D2, INPUT_PULLUP);
  49.  
  50.     // Begin the EasyButton instance
  51.     changemodebutton.begin();
  52.  
  53.     // Attach the onPressed event handler to the button
  54.     changemodebutton.onPressed([]() {
  55.         Serial.println("Change mode button pressed");
  56.     });
  57. }
  58.  
  59. void loop(void)
  60. {
  61.     // Read the state of the button
  62.     changemodebutton.read();
  63. }
  64.  
  65. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement