Advertisement
pleasedontcode

Button Detection rev_02

Aug 25th, 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 compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-08-25 15:15:33
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Utilize the Serial Monitor at 9600 baud rate to */
  21.     /* output "Hello" every second, ensuring proper */
  22.     /* initialization in the setup function and */
  23.     /* consistent timing in the loop function using */
  24.     /* delay. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t button_PushButton_PIN_D4      = 4;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  39. // Instance of the button using the EasyButton class
  40. EasyButton button(button_PushButton_PIN_D4); // Correctly initializing the EasyButton instance
  41.  
  42. void setup(void)
  43. {
  44.     // Initialize Serial for debugging purposes at 9600 baud rate
  45.     Serial.begin(9600);
  46.     Serial.println();
  47.     Serial.println(">>> EasyButton example <<<");
  48.  
  49.     // Initialize the button
  50.     button.begin(); // Call begin() to set up the button
  51.     button.onPressed([]() { // Lambda function to handle button press
  52.         Serial.println("Button pressed");
  53.     });
  54. }
  55.  
  56. void loop(void)
  57. {
  58.     // Continuously read the status of the button
  59.     button.read(); // Read the button state
  60.    
  61.     // Output "Hello" every second
  62.     Serial.println("Hello"); // Print "Hello" to the Serial Monitor
  63.     delay(1000); // Wait for 1 second
  64. }
  65.  
  66. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement