const int redPin = 11;
const int greenPin = 10;
const int bluePin = 9;
const int buttonPin = 2;
int currentColor = 0;
int numColors = 7; // Change this to the number of colors you want to cycle through
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP); // Enable the internal pull-up resistor
}
void loop() {
int buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
// Button pressed, change to the next color
currentColor = (currentColor + 1) % numColors;
delay(200); // Debounce the button
}
// Call a function to set the LED color based on the current color index
setRGBColor(currentColor);
}
void setRGBColor(int colorIndex) {
// Define the RGB values for each color
int colors[][3] = {
{255, 0, 0}, // Red
{0, 255, 0}, // Green
{0, 0, 255}, // Blue
{255, 255, 0}, // Yellow
{0, 255, 255}, // Cyan
{255, 0, 255}, // Magenta
{255, 255, 255} // White
// Add more colors if needed
};
analogWrite(redPin, colors[colorIndex][0]);
analogWrite(greenPin, colors[colorIndex][1]);
analogWrite(bluePin, colors[colorIndex][2]);
}