Using an Uno and Arduino 1.8.12
I'm trying to use the Fade.ino example code (loop portion below as that's what relevant here) to play with a logic analyzer. When I run the code I see (with the logic analyzer) a series of PWM pulses with PWM period of 2ms and a gradually increasing and then decreasing duty-cycle that appears appropriate to the loop code. What I don't understand is why I don't see the 30ms delay until the PWM pulses have run their ranges from 0 - 255 or 255 - 0.
My expectation had been to see a 30ms delay after each PWM pulse (so something like a 2ms+30ms PWM period). I thought that delay() would block so that the loop and therefore the analogWrite / PWM update would wait before continuing to the next increment. I also tried to reduce the delay to 1ms and found that the PWM period became chaotic - suggesting that the delay is doing something to, perhaps, ensure that one pulse completes before the next? My newb is showing?
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
Thanks much for any help.