Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Button Timer
- - Source Code NOT compiled for: Arduino Pro Mini 5V
- - Source Code created on: 2024-10-08 08:19:44
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* FAÇA COM QUE A HORA SEJA MOSTRADO QUANDO O BOTÃO */
- /* FOR PRESSIONADO */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Function prototype for showing time
- void showTime(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t HI_PushButton_PIN_D2 = 2;
- const uint8_t HI_PushButton_PIN_D3 = 3;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Initialize EasyButton object for the button on pin D2
- EasyButton buttonD2(HI_PushButton_PIN_D2);
- // Initialize EasyButton object for the button on pin D3
- EasyButton buttonD3(HI_PushButton_PIN_D3);
- /****** FUNCTION DEFINITIONS *****/
- void setup(void)
- {
- // Start serial communication for debugging
- Serial.begin(115200);
- Serial.println();
- Serial.println(">>> EasyButton pressed example <<<");
- // Set up the button pins as input with pull-up resistors
- pinMode(HI_PushButton_PIN_D2, INPUT_PULLUP);
- pinMode(HI_PushButton_PIN_D3, INPUT_PULLUP);
- // Initialize the EasyButton instances
- buttonD2.begin();
- buttonD3.begin();
- // Set up the onPressed callback for button D2
- buttonD2.onPressed(showTime); // Show time when button D2 is pressed
- }
- void loop(void)
- {
- // Read the button states
- buttonD2.read();
- buttonD3.read();
- }
- // Function to show the current time when the button is pressed
- void showTime()
- {
- // Get the current time
- unsigned long currentTime = millis(); // Get time in milliseconds since the Arduino started
- Serial.print("Current Time: ");
- Serial.print(currentTime);
- Serial.println(" ms");
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement