/********* 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: Random LED Toggle - Source Code compiled for: Arduino Nano - Source Code created on: 2024-01-22 13:34:14 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* вмикає рандомно один з двух світлодіодів при */ /* натисканні кнопки */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include #include /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t knopka_PushButton_PIN_D2 = 2; /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t svitlo_LED_PIN_D3 = 3; const uint8_t svitlo1_LED_PIN_D4 = 4; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ EasyButton button(knopka_PushButton_PIN_D2); void setup(void) { // put your setup code here, to run once: pinMode(knopka_PushButton_PIN_D2, INPUT_PULLUP); pinMode(svitlo_LED_PIN_D3, OUTPUT); pinMode(svitlo1_LED_PIN_D4, OUTPUT); button.begin(); // Set initial state of LEDs to OFF digitalWrite(svitlo_LED_PIN_D3, LOW); digitalWrite(svitlo1_LED_PIN_D4, LOW); } void loop(void) { // put your main code here, to run repeatedly: button.read(); // Check if button is pressed if (button.isPressed()) { // Generate a random number (0 or 1) int randomNumber = random(2); // Turn on one of the LEDs based on the random number if (randomNumber == 0) { digitalWrite(svitlo_LED_PIN_D3, HIGH); digitalWrite(svitlo1_LED_PIN_D4, LOW); } else { digitalWrite(svitlo_LED_PIN_D3, LOW); digitalWrite(svitlo1_LED_PIN_D4, HIGH); } } else { // Turn off both LEDs if the button is not pressed digitalWrite(svitlo_LED_PIN_D3, LOW); digitalWrite(svitlo1_LED_PIN_D4, LOW); } }