From df8d22a440acd8f01099f51af399c40563268607 Mon Sep 17 00:00:00 2001 From: YakovL Date: Sun, 10 Jul 2016 18:31:42 +0300 Subject: [PATCH] fix the boundary check ..so that changing fadeAmount (to, say, 7) doesn't break the algorithm making an infinit loop (see https://github.com/arduino/Arduino/issues/5115) --- build/shared/examples/01.Basics/Fade/Fade.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/shared/examples/01.Basics/Fade/Fade.ino b/build/shared/examples/01.Basics/Fade/Fade.ino index 1839ceca268..727d1484b21 100644 --- a/build/shared/examples/01.Basics/Fade/Fade.ino +++ b/build/shared/examples/01.Basics/Fade/Fade.ino @@ -32,8 +32,8 @@ void loop() { brightness = brightness + fadeAmount; // reverse the direction of the fading at the ends of the fade: - if (brightness == 0 || brightness == 255) { - fadeAmount = -fadeAmount ; + if (brightness <= 0 || brightness >= 255) { + fadeAmount = -fadeAmount; } // wait for 30 milliseconds to see the dimming effect delay(30);