Skip to content

Commit e8dc43e

Browse files
authored
fix the boundary check
..so that changing fadeAmount (to, say, 7) doesn't break the algorithm making an infinit loop (see arduino/Arduino#5115)
1 parent f3e657a commit e8dc43e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

examples/01.Basics/Fade/Fade.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ void loop() {
3232
brightness = brightness + fadeAmount;
3333

3434
// reverse the direction of the fading at the ends of the fade:
35-
if (brightness == 0 || brightness == 255) {
36-
fadeAmount = -fadeAmount ;
35+
if (brightness <= 0 || brightness >= 255) {
36+
fadeAmount = -fadeAmount;
3737
}
3838
// wait for 30 milliseconds to see the dimming effect
3939
delay(30);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy