Advertisement
pleasedontcode

Button Detection rev_01

Aug 25th, 2024
101
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-25 15:13:28
  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. /****** 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 button_PushButton_PIN_D4      = 4;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  38. // Instance of the button using the EasyButton class
  39. EasyButton button(button_PushButton_PIN_D4); // Correctly initializing the EasyButton instance
  40.  
  41. void setup(void)
  42. {
  43.     // Initialize Serial for debugging purposes at 9600 baud rate
  44.     Serial.begin(9600);
  45.     Serial.println();
  46.     Serial.println(">>> EasyButton example <<<");
  47.  
  48.     // Initialize the button
  49.     button.begin(); // Call begin() to set up the button
  50.     button.onPressed([]() { // Lambda function to handle button press
  51.         Serial.println("Button pressed");
  52.     });
  53. }
  54.  
  55. void loop(void)
  56. {
  57.     // Continuously read the status of the button
  58.     button.read(); // Read the button state
  59.    
  60.     // Output "Hello" every second
  61.     Serial.println("Hello"); // Print "Hello" to the Serial Monitor
  62.     delay(1000); // Wait for 1 second
  63. }
  64.  
  65. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement