Advertisement
pleasedontcode

Button Timer rev_01

Oct 8th, 2024
69
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 Timer
  13.     - Source Code NOT compiled for: Arduino Pro Mini 5V
  14.     - Source Code created on: 2024-10-08 08:19:44
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* FAÇA COM QUE A HORA SEJA MOSTRADO  QUANDO O BOTÃO */
  21.     /* FOR PRESSIONADO */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. // Function prototype for showing time
  32. void showTime(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t HI_PushButton_PIN_D2      = 2;
  36. const uint8_t HI_PushButton_PIN_D3      = 3;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. // Initialize EasyButton object for the button on pin D2
  40. EasyButton buttonD2(HI_PushButton_PIN_D2);
  41. // Initialize EasyButton object for the button on pin D3
  42. EasyButton buttonD3(HI_PushButton_PIN_D3);
  43.  
  44. /****** FUNCTION DEFINITIONS *****/
  45. void setup(void)
  46. {
  47.     // Start serial communication for debugging
  48.     Serial.begin(115200);
  49.     Serial.println();
  50.     Serial.println(">>> EasyButton pressed example <<<");
  51.  
  52.     // Set up the button pins as input with pull-up resistors
  53.     pinMode(HI_PushButton_PIN_D2, INPUT_PULLUP);
  54.     pinMode(HI_PushButton_PIN_D3, INPUT_PULLUP);
  55.  
  56.     // Initialize the EasyButton instances
  57.     buttonD2.begin();
  58.     buttonD3.begin();
  59.  
  60.     // Set up the onPressed callback for button D2
  61.     buttonD2.onPressed(showTime); // Show time when button D2 is pressed
  62. }
  63.  
  64. void loop(void)
  65. {
  66.     // Read the button states
  67.     buttonD2.read();
  68.     buttonD3.read();
  69. }
  70.  
  71. // Function to show the current time when the button is pressed
  72. void showTime()
  73. {
  74.     // Get the current time
  75.     unsigned long currentTime = millis(); // Get time in milliseconds since the Arduino started
  76.     Serial.print("Current Time: ");
  77.     Serial.print(currentTime);
  78.     Serial.println(" ms");
  79. }
  80.  
  81. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement