const byte pinR = 9;
const byte pinG = 10;
const byte pinB = 11;
void setColor(byte red, byte green, byte blue) {
analogWrite(pinR, red);
analogWrite(pinG, green);
analogWrite(pinB, blue);
}
void fadeChannel(byte pin, bool fadeUp) {
if (fadeUp) {
for (int i = 0; i <= 255; i++) {
analogWrite(pin, i);
delay(10);
}
} else {
for (int i = 255; i >= 0; i--) {
analogWrite(pin, i);
delay(10);
}
}
}
void setup() {
Serial.begin(9600);
pinMode(pinR, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(pinB, OUTPUT);
setColor(0, 0, 0);
}
void loop() {
// 1. Основные цвета
Serial.println("RED");
setColor(255, 0, 0);
delay(1000);
Serial.println("GREEN");
setColor(0, 255, 0);
delay(1000);
Serial.println("BLUE");
setColor(0, 0, 255);
delay(1000);
Serial.println("YELLOW");
setColor(255, 255, 0);
delay(1000);
Serial.println("CYAN");
setColor(0, 255, 255);
delay(1000);
Serial.println("MAGENTA");
setColor(255, 0, 255);
delay(1000);
// Плавное разгорание и затухание (ШИМ)
setColor(0, 0, 0);
Serial.println("FADE RED");
fadeChannel(pinR, true); // плавно включаем
fadeChannel(pinR, false); // плавно выключаем
//Выключение
Serial.println("OFF");
setColor(0, 0, 0);
delay(1000);
}