Advertisement
pleasedontcode

Button Detection rev_03

Oct 29th, 2024
66
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: ESP8266 NodeMCU V1.0
  14.     - Source Code created on: 2024-10-29 23:20:58
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* print on serial push button. */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /* START CODE */
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t but_PushButton_PIN_D1 = 1;
  34.  
  35. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  36. EasyButton button(but_PushButton_PIN_D1); // Instance of the button
  37.  
  38. // Callback function to be called when the button is pressed.
  39. void onPressed() {
  40.     Serial.println("Button pressed"); // Print message on serial
  41. }
  42.  
  43. void setup(void) {
  44.     // put your setup code here, to run once:
  45.     Serial.begin(115200); // Initialize Serial for debugging purposes
  46.     Serial.println(); // Print a new line
  47.     Serial.println(">>> EasyButton pressed example <<<"); // Print example header
  48.  
  49.     pinMode(but_PushButton_PIN_D1, INPUT_PULLUP); // Set the button pin as input with pull-up resistor
  50.  
  51.     button.begin(); // Initialize the button
  52.     button.onPressed(onPressed); // Add the callback function for button press
  53. }
  54.  
  55. void loop(void) {
  56.     // Continuously read the status of the button.
  57.     button.read(); // Read the button state
  58. }
  59.  
  60. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement