我将在下面发布的代码不应该允许我将 RGB LED 从 0 淡化到 255,然后在无限循环中回到 0 等等吗?
目前它只是逐渐变大,但它并没有消失,它确实闪烁了一下,但随后又在 255 处完全供电。
void setup()
{
Serial.begin(9600);
pinMode(greenPin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
fade = 0;
}
void loop()
{
while(fade < 256)
{
analogWrite(redPin, fade);
delay(30);
analogWrite(greenPin, fade );
delay(30);
analogWrite(bluePin, fade);
delay(30);
fade++;
}
while(fade > 0)
{
analogWrite(redPin, fade);
delay(30);
analogWrite(greenPin, fade );
delay(30);
analogWrite(bluePin, fade);
delay(30);
fade--;
}
}