Hello. I was testing the basic examples from the IDE.
I found that code of the sketch from basic examples, has something weird for me in the IF statement.
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;
}
Serial.println(fadeAmount);
Serial.println(brightness);
// wait for 30 milliseconds to see the dimming effect
delay(30);
I think the line
if (brightness <= 0 || brightness >= 255)
should be;
if (brightness == 0 || brightness == 255)
In the first case, brightnes is never going to be under 0 or over 255.
Why using "<= , >=" then ?
it works exactly the same as the second case, that I think is the correct one.
I tested both and read the serial. The output is the same.