Advertisement
pleasedontcode

**Button Debounce** rev_04

Nov 12th, 2024
76
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 Debounce**
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-11-13 05:57:30
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* the robot I talked with. so all I need is to talk */
  21.     /* with the ai from the microphone and listen to the */
  22.     /* answer from the speaker so I have > breadboard and */
  23.     /* esp32 and wire and microphone and speaker and */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  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 speaker_PushButton_PIN_D4 = 4;
  37.  
  38. /***** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. EasyButton button(speaker_PushButton_PIN_D4); // Create an EasyButton instance for the push button
  40.  
  41. void setup(void)
  42. {
  43.     // Initialize the button
  44.     button.begin(); // Initialize the EasyButton instance
  45.     pinMode(speaker_PushButton_PIN_D4, INPUT_PULLUP); // Set the button pin as input with pull-up resistor
  46. }
  47.  
  48. void loop(void)
  49. {
  50.     // Update the button state
  51.     button.update(); // Update the button state
  52.  
  53.     // Check if the button is pressed
  54.     if (button.isPressed()) {
  55.         // Code to handle button press (e.g., send audio to speaker)
  56.     }
  57. }
  58.  
  59. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement