Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* 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 Control - Source Code compiled for: Arduino Uno - Source Code created on: 2024-09-30 16:23:30 ********* 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
//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 } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)