const int redPin = 16;
const int greenPin = 17;
const int bluePin = 18;
// Función para establecer el color RGB con PWM (0-255 para cada componente)
void setLedColorPWM(uint8_t red, uint8_t green, uint8_t blue) {
// Para un LED de ánodo común, un valor más alto significa menos brillo (más tiempo en LOW)
analogWrite(redPin, 255 - red);
analogWrite(greenPin, 255 - green);
analogWrite(bluePin, 255 - blue);
}
void setup() {
Serial.begin(115200);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// Ejemplo de uso:
setLedColorPWM(255, 0, 0); // Rojo brillante
delay(1000);
setLedColorPWM(0, 255, 0); // Verde brillante
delay(1000);
setLedColorPWM(0, 0, 255); // Azul brillante
delay(1000);
setLedColorPWM(100, 50, 150); // Un color personalizado
delay(1000);
setLedColorPWM(0, 0, 0); // Apagado
delay(1000);
}