Advertisement
pleasedontcode

"Button Detection" rev_01

May 27th, 2024
591
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-05-27 13:29:52
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop a Ben10 Omnitrix project using an Arduino */
  21.     /* with a TFT round display and a push button */
  22.     /* connected to pin D4. Utilize the EasyButton */
  23.     /* library for button handling. Ensure the setup */
  24.     /* initializes the button with INPUT_PULLUP mode. */
  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. void onPressed(void);  // Prototype for the button press handler function
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t TFTrounddisplay_PushButton_PIN_D4 = 4;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. EasyButton button(TFTrounddisplay_PushButton_PIN_D4);  // Initialize EasyButton with the pin number
  40.  
  41. void onPressed(void)
  42. {
  43.   Serial.println("Button pressed");
  44. }
  45.  
  46. void setup(void)
  47. {
  48.   // put your setup code here, to run once:
  49.   Serial.begin(115200);
  50.   Serial.println();
  51.   Serial.println(">>> EasyButton pressed example <<<");
  52.  
  53.   pinMode(TFTrounddisplay_PushButton_PIN_D4, INPUT_PULLUP);  // Set the button pin as INPUT_PULLUP
  54.   button.begin();  // Initialize the button
  55.   button.onPressed(onPressed);  // Attach the onPressed handler
  56. }
  57.  
  58. void loop(void)
  59. {
  60.   // put your main code here, to run repeatedly:
  61.   button.read();  // Read the button state
  62. }
  63.  
  64. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement