Advertisement
pleasedontcode

**Button Handling** rev_05

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 Handling**
  13.     - Source Code compiled for: ESP8266 NodeMCU V1.0
  14.     - Source Code created on: 2024-10-30 00:02:47
  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);  // Added missing semicolon
  30. void loop(void);   // Added missing semicolon
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t but_PushButton_PIN_D1 PROGMEM = 1; // Store in flash memory to save RAM
  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(F("Button pressed")); // Use F() macro to store string in flash memory
  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(F(">>> EasyButton pressed example <<<")); // Use F() macro for flash memory
  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