// Definición de pines
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;
const int buttonPin = 2;
// Variable para almacenar el estado del botón
bool buttonPressed = false;
bool isBlinking = false;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP); // Configurar el botón con resistencia pull-up interna
// Configurar el LED RGB en blanco (luces de día)
setColor(255, 255, 255);
}
void loop() {
// Leer el estado del botón
if (digitalRead(buttonPin) == LOW && !buttonPressed) { // Si se presiona el botón
buttonPressed = true;
isBlinking = true;
for (int i = 0; i < 5; i++) {
setColor(255, 255, 0); // Encender en amarillo (R:255, G:255, B:0)
delay(500); // Esperar 500 milisegundos
setColor(0, 0, 0); // Apagar el LED
delay(500); // Esperar 500 milisegundos
}
// Volver a encender en azul claro
setColor(135, 206, 235);
isBlinking = false;
}
if (digitalRead(buttonPin) == HIGH) { // Resetear el estado del botón cuando se suelte
buttonPressed = false;
}
}
void setColor(int red, int green, int blue) {
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}