User manual

110 lcd.createChar(0, MyChar0);
111 lcd.createChar(1, MyChar1);
112 lcd.createChar(2, MyChar2);
113 lcd.createChar(3, MyChar3);
114 lcd.createChar(4, MyChar4);
115 lcd.createChar(5, MyChar5);
116
117 lcd.begin(16, 2);
118 }
119
120 void loop()
121 {
122 double percent;
123
124 if(flag == 0)value++;
125 if(flag == 1)value--;
126 if(value > 1024)flag=1;
127 else if(value == 0)flag=0;
128
129 percent = value / 1024.0 * 100.0;
130 draw_bargraph(percent);
131 delay(10);
132 }
The individual segments of the bar chart display are specified
with the arrays
MyChar0
to
MyChar5
. The program code already shows
how the segments fill with ones bottom-up array by array. In
the
Setup()
-function, the characters are created
with
lcd.createChar()
.
In the
Loop()
-function, an Up/Down counter that we know from the
preceding experiments is used again. However, this time, it
counts from 0 to 1,024. This way the counter could easily be
replaced by an Arduino™-analogue input that covers a value range
of 0 to 1,023. The counter value is converted to percent and
handed over to the function
draw_bargraph()
.
The
draw_bargraph()
-function is exciting. Here, the bar chart
display is put together and displayed. Every time the function
is called, the cursor will be set to position (0, 0). This is
the starting position to re-draw the display. In the first row,
we output the percentage value of the variable
percent
and write
a percentage sign behind it. The percentage sign will be followed
by two spaces to clear the display from tens or hundreds offset.
The digital value output in percent is thus complete.
Then we use
setCursor(0,
1)
to place the cursor in the lower, i.e.
the second row of the LCD. To divide the percentage value, which
goes from 0 to 100 % into the 80 individual areas (pixels), we