/********* 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 LED - Source Code NOT compiled for: Arduino Nano - Source Code created on: 2024-04-25 11:48:52 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Ensure LED diode turns on for 50ms after pressing */ /* the Button. It should turn off after 50ms, even if */ /* the button is still pressed. Allow reactivation */ /* only after a 2s delay. Button is connected to pin */ /* 6, diode is connected to pin 7. */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void updateOutputs(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t Button_PIN = 6; /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t LED_PIN = 7; /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ bool LED_state = LOW; unsigned long lastDeactivationTime = 0; void setup(void) { // put your setup code here, to run once: pinMode(Button_PIN, INPUT_PULLUP); pinMode(LED_PIN, OUTPUT); } void loop(void) { // put your main code here, to run repeatedly: if (digitalRead(Button_PIN) == LOW) { // Button is pressed digitalWrite(LED_PIN, HIGH); // Turn on LED delay(50); // Keep LED on for 50ms digitalWrite(LED_PIN, LOW); // Turn off LED lastDeactivationTime = millis(); // Record the time of deactivation } // Check if reactivation is allowed after 2s delay if (millis() - lastDeactivationTime >= 2000) { updateOutputs(); // Refresh output data } } void updateOutputs() { // Update LED state based on the condition if (digitalRead(Button_PIN) == HIGH) { LED_state = LOW; // Reset LED state } digitalWrite(LED_PIN, LED_state); } /* END CODE */