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 Management
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-09-30 16:21:39
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* you have to make sure that the first loop repeats */
- /* until the button is pressed. if it is pressed */
- /* while Arduino is executing the first loop, Arduino */
- /* must be able to remember that the key was pressed */
- /* to thus start the second loop if the memory that */
- /* the */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t button_PushButton_PIN_D2 = 2;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Instance of the button using the EasyButton library.
- EasyButton button(button_PushButton_PIN_D2); // Initialize the EasyButton object with the button pin
- // Callback function to be called when the button is pressed for the given duration.
- void onPressedForDuration()
- {
- // Code to be executed when the button is pressed for the given duration.
- }
- // Variables to manage the state of the loops
- bool firstLoopComplete = false; // Flag to indicate if the first loop is complete
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(button_PushButton_PIN_D2, INPUT_PULLUP); // Set the button pin as input with pull-up resistor
- // Initialize the button.
- button.begin();
- // Add the callback function to be called when the button is pressed for at least the given time.
- button.onPressedFor(2000, onPressedForDuration); // Set the duration for the button press
- }
- void loop(void)
- {
- // Continuously read the status of the button
- button.read(); // Update button state
- // Check if the button is pressed
- if (button.isPressed()) {
- // If the button is pressed, mark the first loop as incomplete
- firstLoopComplete = true; // Remember that the button was pressed
- }
- // First loop logic
- if (!firstLoopComplete) {
- // Execute the first loop code here
- // This loop will repeat until the button is pressed
- // Add your first loop code here
- } else {
- // Second loop logic
- // Execute the second loop code here
- // This loop will execute after the button has been pressed
- // Add your second loop code here
- // Optionally, reset the flag if you want to return to the first loop after the second loop
- firstLoopComplete = false; // Reset the flag to allow returning to the first loop
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement