Advertisement
pleasedontcode

Button Detection rev_01

Aug 9th, 2024
129
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: ESP32 DevKit V1
  14.     - Source Code created on: 2024-08-09 17:03:54
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The project requires integration of the EasyButton */
  21.     /* library to handle button interactions on digital */
  22.     /* pin D4, ensuring it operates with INPUT_PULLUP for */
  23.     /* enhanced input stability. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t boton_PushButton_PIN_D4 = 4;
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. // Initialize the EasyButton object for the defined pin
  38. EasyButton button(boton_PushButton_PIN_D4);
  39.  
  40. /****** FUNCTION DEFINITIONS *****/
  41.  
  42. // Function to be called when the button is pressed
  43. void onButtonPressed() {
  44.   Serial.println("Button pressed");
  45. }
  46.  
  47. void setup(void)
  48. {
  49.     // Start serial communication for debugging
  50.     Serial.begin(115200);
  51.    
  52.     // Set the button pin mode to INPUT_PULLUP for enhanced input stability
  53.     pinMode(boton_PushButton_PIN_D4, INPUT_PULLUP);
  54.    
  55.     // Initialize the button with the defined pin
  56.     button.begin();
  57.    
  58.     // Attach the onPressed function to the button
  59.     button.onPressed(onButtonPressed);
  60. }
  61.  
  62. void loop(void)
  63. {
  64.     // Call the read function to check the button state
  65.     button.read();
  66. }
  67.  
  68. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement