User manual

use the
Map()
-function. This scales the input value
percent
, from
0 to 100 to the output value from 0 to 80. The variable
percent
then
holds a value between 0 and 80, depending on the input val-
ue
percent.
Now we determine the value of
percent
by dividing the number of
boxes to be filled entirely by 5, and write the result into the
variable
c1
. The modulo operation % determines the rest or the
partial filling. We will write this value into the variable
c2
.
Now we know how many boxes are to be filled completely and how
many are filled only partially.
In the following
For()
-loop, we will count up until all filled
boxes are reached, and write a full box onto the LCD in every
loop passage. Since every subsequent output at the LCD auto-
matically moves the characters by one, we will have a bar with
full boxes at the end of the loop. This point of the program also
shows that the
For()
-loop uses no braces. In the
For()
-loop, the
compiler only takes the subsequent row into the loop. In this
case, this would be the call of
lcd.write(byte(5))
. After completing
this first box loop, the box with the partial filling is written
onto the LCD. This leads to a bar that is built pixel by pixel
on the LCD.
Example
The percentage value 43 is to be displayed. We divide the number
43 by 5, which makes 8.6. Since the variable c1 is declared as
byte, only an 8 will be saved in it. Modulo 5 from 43 is 3, which
means three partial strokes.
If the value reduces again, we need to delete the superfluous
characters from the LCD. A new operation, which is called
conditional expression or ternary selection operator, is added
.
Generally, the entire thing can be viewed like an
If-Else-instruction, but it is only an abbreviated C annotation.
The syntax for the conditional instruction would be: Condition
? Expression1 : Expression2
This seems familiar to you, doesn't it? It generally is no
different from:
001 if(condition)
002 {
003 // Expression1
004 }
005 else
006 {
007 // Expression2
008 }
009