I am seeing a "blip" in LED brightness when trying to fade a red LED on an Arduino UNO.
This code demonstrates the "blip" seen in brightness right after a 254, 255, 0 sequence. When the brightness is then set to 1, the actual brightness is much higher for a short period of time. The blip is not seen during the entire delay interval, just at the beginning.
I see the blip every time except for the very first cycle, before the 255 to 0 transition has ever happened.
My best guess is that there is a PWM "accumulation" that is not seen when the brightness is set to zero, but it is used when the brightness is set to a non-zero value.
/*
FadeBlip
Derived from Fade.ino.
*/
int led = 9;
int brightness = 0;
int fadeAmount = 1;
int skipBegin = 5;
int skipEnd = 254;
// If you try a shorter delay, you must make the skip range smaller
// to pick out the blip. If you try a longer delay, the blip is not
// as bright.
int delayms = 1000;
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
delay(1000); // give us time to bring up serial monitor
}
void loop() {
Serial.println(brightness);
analogWrite(led, brightness);
brightness = brightness + fadeAmount;
// skip the boring middle values
if (skipBegin < brightness && brightness < skipEnd)
brightness = skipEnd;
if (brightness > 255)
brightness = 0;
delay(delayms);
}