Advertisement
pleasedontcode

Button Input rev_186

Jan 14th, 2024
65
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 Input
  13.     - Source Code compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-01-14 12:25:28
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* do nothing */
  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 button_PushButton_PIN_D2 = 2;
  33. const uint8_t digitalinput_PIN_D3 = 3;
  34. const uint8_t diginputwithpullup_PIN_D4 = 4;
  35. const uint8_t diginputwithpulldown_PIN_D5 = 5;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. EasyButton button_PushButton(button_PushButton_PIN_D2);
  39. EasyButton digitalinput(digitalinput_PIN_D3);
  40. EasyButton diginputwithpullup(diginputwithpullup_PIN_D4);
  41. EasyButton diginputwithpulldown(diginputwithpulldown_PIN_D5);
  42.  
  43. void setup(void)
  44. {
  45.     // put your setup code here, to run once:
  46.  
  47.     pinMode(button_PushButton_PIN_D2, INPUT_PULLUP);
  48.     pinMode(digitalinput_PIN_D3, INPUT);
  49.     pinMode(diginputwithpullup_PIN_D4, INPUT_PULLUP);
  50.     pinMode(diginputwithpulldown_PIN_D5, INPUT_PULLDOWN);
  51.  
  52.     button_PushButton.begin();
  53.     digitalinput.begin();
  54.     diginputwithpullup.begin();
  55.     diginputwithpulldown.begin();
  56. }
  57.  
  58. void loop(void)
  59. {
  60.     // put your main code here, to run repeatedly:
  61.  
  62.     button_PushButton.read();
  63.     digitalinput.read();
  64.     diginputwithpullup.read();
  65.     diginputwithpulldown.read();
  66.  
  67.     // Add your code logic for handling button events
  68.     if (button_PushButton.wasPressed()) {
  69.         // Button_PushButton was pressed
  70.     }
  71.  
  72.     if (digitalinput.wasReleased()) {
  73.         // digitalinput was released
  74.     }
  75.  
  76.     if (diginputwithpullup.pressedFor(1000)) {
  77.         // diginputwithpullup was pressed for 1 second
  78.     }
  79.  
  80.     if (diginputwithpulldown.releasedFor(500)) {
  81.         // diginputwithpulldown was released for 500 milliseconds
  82.     }
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement