User manual

029 if(flag==0)i++;
030 if(flag==1)i--;
031
032 if(i==255)flag=1;
033 else if(i==0)flag=0;
034
035 analogWrite(Backlight, i);
036
037 previousMillis = currentMillis;
038 }
039 }
The experiment also shows how an automatic up/down counter with
a limit can be put into practice. It is important that the
variable named
flag
receives a defined starting value of 0. When
starting the program, the variable
i
is counted up to 255 . If
we wanted to start at full brightness, we would have to initialise
the variable
flag
with 1 and the variable
i
with 255.
When the counter value
i
of 255 or 0 is reached, the varia-
ble
flag
will always be set from 0 to 1 or from 1 to 0 and the counter
direction will change (i++ increases the counter status, in-
cremented by 1, i-- reduces the counter status, decremented by
1). In the
Loop()
-function, we do not use a break this time, but
determine the time via the function
millis()
. Only when a specified
difference that we have declared in the variable
previousMillis
has
expired will the brightness be changed by one level. This way, the
program will continue to run at full speed outside of the
If()-query. Only if the PWM-value is changed will the throughput
time change a little, since some functions that require a certain
processing time will be called . Here, you can also try to
determine the different throughput times with
the
Millis()
-function that you have already learned about.
DOT-MATRIX-LCD
CLOCK
In many applications, a clock is needed for program control -
either a simple timer, a control to comply with a precise
schedule, or an operating hours counter. The applications that
need a clock are diverse.
The experiment shows how to program a very simple clock yourself.
The program runs in the
Loop()-
function, is finite and counts up
at a cycle of 10-ms. If the counter reading cnt = 100, the time