/********* 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: LED Control - Source Code compiled for: Arduino Uno - Source Code created on: 2024-04-07 10:27:07 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Με το πάτημα του EasyButton που είναι συνδεδεμένο */ /* στον ακροδέκτη D2, το πράσινο LED που είναι */ /* συνδεδεμένο στον ακροδέκτη D4 θα αναβοσβήνει με */ /* ακρίβεια 10 φορές και στη συνέχεια θα σταματήσει */ /* να αναβοσβήνει. */ /****** SYSTEM REQUIREMENT 2 *****/ /* Όταν η πράσινη λυχνία LED, που είναι συνδεδεμένη */ /* στον ακροδέκτη D4, σταματήσει να αναβοσβήνει, η */ /* κόκκινη λυχνία LED, που είναι συνδεδεμένη στην */ /* ακίδα D3, θα πρέπει να ανάβει για 15 δευτερόλεπτα */ /* και μετα να σβηνη */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include //https://github.com/evert-arias/EasyButton /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void onPressedForDuration(); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t tilt_PushButton_PIN_D2 = 2; /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t red_LED_PIN_D3 = 3; const uint8_t green_LED_PIN_D4 = 4; /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ /***** used to store raw data *****/ bool red_LED_PIN_D3_rawData = 0; bool green_LED_PIN_D4_rawData = 0; /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/ /***** used to store data after characteristic curve transformation *****/ float red_LED_PIN_D3_phyData = 0.0; float green_LED_PIN_D4_phyData = 0.0; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ EasyButton button(tilt_PushButton_PIN_D2); void setup(void) { // put your setup code here, to run once: pinMode(tilt_PushButton_PIN_D2, INPUT_PULLUP); pinMode(red_LED_PIN_D3, OUTPUT); pinMode(green_LED_PIN_D4, OUTPUT); } void loop(void) { // put your main code here, to run repeatedly: button.read(); // Continuously read the status of the button updateOutputs(); // Refresh output data } void updateOutputs() { if (button.isPressed()) { // Check if button is pressed // Toggle green LED 10 times for (int i = 0; i < 10; i++) { green_LED_PIN_D4_rawData = !green_LED_PIN_D4_rawData; digitalWrite(green_LED_PIN_D4, green_LED_PIN_D4_rawData); delay(100); } } else { green_LED_PIN_D4_rawData = 0; digitalWrite(green_LED_PIN_D4, green_LED_PIN_D4_rawData); } // Check if green LED has stopped blinking if (!green_LED_PIN_D4_rawData) { // Turn on red LED for 15 seconds red_LED_PIN_D3_rawData = 1; digitalWrite(red_LED_PIN_D3, red_LED_PIN_D3_rawData); delay(15000); // 15 seconds red_LED_PIN_D3_rawData = 0; digitalWrite(red_LED_PIN_D3, red_LED_PIN_D3_rawData); } }