Hello Arduino forum,
Have been working on a circuit based on
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fade
The circuit fades seven LEDs from bright to off
over eight seconds.
The sketch has been studied and some tests done
changing the 'brightness' and the 'fadeAmount'
variables as well as the 'delay(120)' statement
at the end of the sketch.
++++ Tests of the Fade Sketch ++++
The Fade sketch is one of the built in examples
that come with the Arduino IDE:
File > Examples > Basic > Fade
Preconditions:
- Circuit shown in JPG titled 'SPSF ATtiny85, Schematic
dated 250509. - Fade sketch, Fade.ino
Action: Apply power, 5.1 VDC to circuit
Test 250512.1 Sketch as copied from Arduino Examples
Brightness: 0
fadeAmount: 5
Delay: 120
Result: Interval: 12 secs; LEDs: Bright
Test 250512.2
Brightness: 10
fadeAmount: 15
Delay: 120
Result: Interval: 3.8 secs; LEDs: Bright
Test 250512.3
Brightness: 5
fadeAmount: 20
Delay: 120
Result: Interval: 3.3 secs; LEDs: Medium Bright
Test 250512.4
Brightness: 10
fadeAmount: 20
Delay: 500
Result: Interval: 13.5 secs; LEDs: Bright
Change increments visible.
Test 250512.5
Brightness: 0
fadeAmount: 5
Delay: 120
Result: Interval: 12 secs; LEDs: Bright
Test 250512.6
Brightness: 5
fadeAmount: 5
Delay: 120
Result: Interval: 11.5 secs; LEDs: Bright
Test 250512.7
Brightness: 10
fadeAmount: 5
Delay: 120
Result: Interval: 12 secs; LEDs: Medium Bright
Test 250512.8
Brightness: 10
fadeAmount: 5
Delay: 80
Result: Interval: 8 secs; LEDs: Bright
The brightness variable seems to control how far down
the light from the LEDs goes. Above zero the LEDs
never completely turn off
The fadeAmount determines how far the brightness
changes with each increment.
There is strong correlation between Delay values
of ten and the number of seconds the cycle takes.
That is, Delay:80 is about eight seconds and Delay:120
is twelve seconds.
The variable setup in the sketch seems fairly
straight forward as does the void setup {
And I believe I get the statement in the
void loop {
brightness = brightness + fadeAmount;
This is saying "Increment (increase or decrease) the brightness
by the fadeAmount."
The statement that is less clear is
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
I think this statement is saying
If
brightness is less than or equal to zero
or
brightness is greater than or equal to 255
then
fadeAmount is equal to minus fadeAmount
But if the statement is always incrementing the brightness
by minus fadeAmount how do the LEDs ever get brighter?
The statement seems to start off decreasing the brightness.
But how does it increase the brightness?
At the heart of the statement is the double pipe
C++ logical operator which is used to combine
multiple boolean expressions. The double pipe
returns true if either of the expressions are
true.
How does this first decrease the brightness and then
increase the brightness?
Thanks.
Allen




