Advertisement
pleasedontcode

Button Setup rev_191

Jan 14th, 2024
68
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 Setup
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-01-14 12:54:30
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if button is pressed so set out to 128. */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25. #include <EasyButton.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t butt_PushButton_PIN = 4;
  33. const uint8_t dit_PIN_D13 = 13;
  34. const uint8_t ditpullup_PIN_D14 = 14;
  35. const uint8_t ditpulldown_PIN_D16 = 16;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. // Initialize the EasyButton object
  39. EasyButton butt_PushButton(butt_PushButton_PIN);
  40.  
  41. void setup(void)
  42. {
  43.   // Initialize Serial communication with a baud rate of 115200
  44.   Serial.begin(115200);
  45.  
  46.   // Set the output pin to 128 if the button is pressed
  47.   pinMode(dit_PIN_D13, OUTPUT);
  48.  
  49.   // Set the pins as input
  50.   pinMode(ditpullup_PIN_D14, INPUT_PULLUP);
  51.   pinMode(ditpulldown_PIN_D16, INPUT_PULLDOWN);
  52.  
  53.   // Initialize the EasyButton
  54.   butt_PushButton.begin();
  55.  
  56.   // Register a callback function for button pressed event
  57.   butt_PushButton.onPressed([](){
  58.     Serial.println("Button pressed");
  59.    
  60.     // Set the output pin to 128
  61.     digitalWrite(dit_PIN_D13, 128);
  62.   });
  63. }
  64.  
  65. void loop(void)
  66. {
  67.   // Read the button state
  68.   butt_PushButton.read();
  69.  
  70.   // Continue with other tasks
  71.   // ...
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement