/********* 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 Nano - Source Code created on: 2024-01-11 22:28:59 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* spradzaj do nieskończoność czas trwania podania */ /* napiecia do pin 8. Jeśli czas trwania napiecia do */ /* pin 8 jest równy 3000 ms podaj napiecie do pin 8 */ /* do czas trwania 10000 ms i zakoncz podanie */ /* napiecia do pin 8. */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include #include /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void checkButton(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t Button1_PushButton_PIN_D2 = 2; const uint8_t VoltageOutput_PIN_D8 = 8; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ EasyButton button(Button1_PushButton_PIN_D2); // Flag to track if the voltage has been applied to pin 8 bool voltageApplied = false; // Time at which the voltage was applied to pin 8 unsigned long voltageStartTime; void setup(void) { // Initialize the button button.begin(); // Set the button callback function button.onPressedFor(3000, checkButton); // Set the voltage output pin as an output pinMode(VoltageOutput_PIN_D8, OUTPUT); // Initialize the voltage output pin to LOW digitalWrite(VoltageOutput_PIN_D8, LOW); } void loop(void) { // Continuously read the button state button.read(); // Check if the voltage has been applied to pin 8 if (voltageApplied) { unsigned long currentTime = millis(); unsigned long duration = currentTime - voltageStartTime; // Check if the duration is equal to 3000 ms if (duration == 3000) { // Apply voltage to pin 8 for a duration of 10000 ms digitalWrite(VoltageOutput_PIN_D8, HIGH); delay(10000); digitalWrite(VoltageOutput_PIN_D8, LOW); // Reset the flag and start time voltageApplied = false; voltageStartTime = 0; } } } // Callback function called when the button is pressed for the specified duration void checkButton() { // Set the flag and record the start time voltageApplied = true; voltageStartTime = millis(); }