#define RED_PIN 19
#define GREEN_PIN 18
#define BLUE_PIN 25
#define LEDRED 23
#define LEDGREEN 22
#define LEDBLUE 21
#define RED_BUTTON_PIN 34
#define GREEN_BUTTON_PIN 35
#define BLUE_BUTTON_PIN 32
void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
pinMode(LEDRED, OUTPUT);
pinMode(LEDGREEN, OUTPUT);
pinMode(LEDBLUE, OUTPUT);
pinMode(RED_BUTTON_PIN, INPUT_PULLUP);
pinMode(GREEN_BUTTON_PIN, INPUT_PULLUP);
pinMode(BLUE_BUTTON_PIN, INPUT_PULLUP);
setColor(0, 0, 0);
}
void loop() {
// Read the state of each button
int redButtonState = digitalRead(RED_BUTTON_PIN);
int greenButtonState = digitalRead(GREEN_BUTTON_PIN);
int blueButtonState = digitalRead(BLUE_BUTTON_PIN);
// If only one button is pressed, turn on the corresponding LED
if (redButtonState == LOW && greenButtonState == HIGH && blueButtonState == HIGH) {
setColor(255, 0, 0); // Red
} else if (greenButtonState == LOW && redButtonState == HIGH && blueButtonState == HIGH) {
setColor(0, 255, 0); // Green
} else if (blueButtonState == LOW && redButtonState == HIGH && greenButtonState == HIGH) {
setColor(0, 0, 255); // Blue
}
// If two buttons are pressed, mix the corresponding colors
else if (redButtonState == LOW && greenButtonState == LOW && blueButtonState == HIGH) {
setColor(255, 255, 0); // Yellow (Red + Green)
} else if (redButtonState == LOW && blueButtonState == LOW && greenButtonState == HIGH) {
setColor(255, 0, 255); // Magenta (Red + Blue)
} else if (greenButtonState == LOW && blueButtonState == LOW && redButtonState == HIGH) {
setColor(0, 255, 255); // Cyan (Green + Blue)
}
// If all buttons are pressed, turn on the RGB LED to white
else if (redButtonState == LOW && greenButtonState == LOW && blueButtonState == LOW) {
setColor(255, 255, 255); // White
}
// If no button is pressed, turn off LEDs
else {
setColor(0, 0, 0); // Turn off LEDs if no button is pressed
}
}
void setColor(int red, int green, int blue) {
analogWrite(RED_PIN, red);
analogWrite(GREEN_PIN, green);
analogWrite(BLUE_PIN, blue);
}