const int buttonPin = 13;
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
bool ledOn = false;
bool lastButtonState = HIGH;
unsigned long lastDebounceTime = 0;
const unsigned long debounceDelay = 50;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
//setColor(0, 0, 0);
}
void loop() {
bool reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (lastButtonState == HIGH && reading == LOW) {
ledOn = !ledOn;
if (ledOn) {
//setColor(255, 0, 255); // Magenta (R + B)
analogWrite(redPin, HIGH);
} else {
//setColor(0, 0, 0); // Off
analogWrite(redPin, LOW);
}
}
}
lastButtonState = reading;
}
// void setColor(int r, int g, int b) {
// analogWrite(redPin, r);
// analogWrite(greenPin, g);
// analogWrite(bluePin, b);
// }