/********* 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: "RGB Control" - Source Code compiled for: Arduino Uno - Source Code created on: 2023-12-09 18:59:22 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* RUN A RGB LED USING 2 BUTTONS the buttons run 3 */ /* colors green yellow red consecutively button 1 */ /* changes colors up and button 2 changes colors down */ /* the buttons can only go up or down the colors and */ /* nothing else */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include #include /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t button1_PushButton_PIN_D2 = 2; const uint8_t button2_PushButton_PIN_D3 = 3; /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t led_LEDRGB_Red_PIN_D4 = 4; const uint8_t led_LEDRGB_Green_PIN_D5 = 5; const uint8_t led_LEDRGB_Blue_PIN_D6 = 6; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ EasyButton button1(button1_PushButton_PIN_D2); EasyButton button2(button2_PushButton_PIN_D3); enum RGBColor { GREEN, YELLOW, RED }; RGBColor currentColor = GREEN; void setup(void) { // put your setup code here, to run once: pinMode(button1_PushButton_PIN_D2, INPUT_PULLUP); pinMode(button2_PushButton_PIN_D3, INPUT_PULLUP); pinMode(led_LEDRGB_Red_PIN_D4, OUTPUT); pinMode(led_LEDRGB_Green_PIN_D5, OUTPUT); pinMode(led_LEDRGB_Blue_PIN_D6, OUTPUT); } void changeColorUp() { if (currentColor == GREEN) { currentColor = YELLOW; } else if (currentColor == YELLOW) { currentColor = RED; } else if (currentColor == RED) { currentColor = GREEN; } } void changeColorDown() { if (currentColor == GREEN) { currentColor = RED; } else if (currentColor == YELLOW) { currentColor = GREEN; } else if (currentColor == RED) { currentColor = YELLOW; } } void updateLEDColor() { if (currentColor == GREEN) { digitalWrite(led_LEDRGB_Red_PIN_D4, LOW); digitalWrite(led_LEDRGB_Green_PIN_D5, HIGH); digitalWrite(led_LEDRGB_Blue_PIN_D6, LOW); } else if (currentColor == YELLOW) { digitalWrite(led_LEDRGB_Red_PIN_D4, HIGH); digitalWrite(led_LEDRGB_Green_PIN_D5, HIGH); digitalWrite(led_LEDRGB_Blue_PIN_D6, LOW); } else if (currentColor == RED) { digitalWrite(led_LEDRGB_Red_PIN_D4, HIGH); digitalWrite(led_LEDRGB_Green_PIN_D5, LOW); digitalWrite(led_LEDRGB_Blue_PIN_D6, LOW); } } void loop(void) { // put your main code here, to run repeatedly: button1.read(); button2.read(); if (button1.wasPressed()) { changeColorUp(); } else if (button2.wasPressed()) { changeColorDown(); } updateLEDColor(); }