Joy-it RB-LCD-16x2 Bedienungsanleitung

Joy-it Spielzeug RB-LCD-16x2

Lesen Sie kostenlos die 📖 deutsche Bedienungsanleitung fĂŒr Joy-it RB-LCD-16x2 (15 Seiten) in der Kategorie Spielzeug. Dieser Bedienungsanleitung war fĂŒr 12 Personen hilfreich und wurde von 2 Benutzern mit durchschnittlich 4.5 Sternen bewertet

Seite 1/15
Beginner’s Guide
to the
PI LCD
Part 4: Graphics
, W8BH
1) INTRODUCTION
In the rst three parts of this series, we learned how to display text and simple graphics on
the LCD board (available from mypishop.com). It’s time to kick it up a notch, and create a
suite of useful graphics functions. We’ll even create a large-digit clock. You may have
purchased either a 16x2 or a 20x4 display with your kit. In this write-up I’ll be using the
20x4 display. When it comes to graphics, bigger is better!
2) SIMPLE HORIZONTAL BAR GRAPHS
An important requirement for creating detailed graphics is that the display device is dot-
addressable. In other words, each display pixel can be individually addressed and
programmed, separate from its neighbors. Sadly, our HD44780 controller does not give us
a dot-addressable LCD display. We get only pre-determined characters, plus 8 characters
of our own design. How can we possibly do artwork on that?
Well, we can’t. Go ahead, prove me wrong. Detailed graphics with this LCD module are
devilishly hard to do. But that doesn’t mean we can’t create useful, simpler graphics. Bar
graphs, for example.
First, consider a single, horizontal
bar graph. Here is our 20x4
display, with a horizontal bar that is
12 characters wide. If we need to
display data that over a small
integer range, like 0-15, we can do it by repeating the solid block (0xFF) character for the
desired length. You might code it like this:
def HorizBar(row,startCol,length):
GotoXY(row,startCol) #go to starting position
for count in range(length):
SendByte(0xFF,True) #display bar of desired length
This simple code works, and is surprisingly useful. You aren’t limited to small ranges: just
scale the desired range to 0-15 by the appropriate conversion factor. But your graph will
always look a little coarse and chunky, since there are a limited number of possible data
values/lengths.
3 BETTER HORIZONTAL BAR GRAPHS)
The graph will look better if we improve the horizontal resolution. But how? We can get a
ve-fold improvement in resolution if we use the simple graphics from Part 3.
Consider the individual character. It contains 40 individual pixel “dots”,
arranged in an 8 row, 5 column grid. We can’t access each individual
pixel, but we can create custom symbols like this vertical bar. Display this
one to the right of the 12-character bar above, and you’ve just made a bar
of length 12.2!
Let’s make a set of vertical bar symbols, progressively increasing the
number of columns in the symbol
0.2 0.4 0.6 0.8 1.0
Now we can increment the length of our horizontal bar in fractions of a character, improving
the horizontal resolution of our graph. ime to code it. First, create the set of symbols, It’s t
like we did in part 3:
horizontalBars = [
[ 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 ], #1 bar
[ 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18 ], #2 bars
[ 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C ], #3 bars
[ 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E ], #4 bars
[ 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F ] #5 bars
]
Now we need a routine to draw the horizontal bar for a given length. To simplify things, let’s
stay with integer lengths, and give each vertical bar a length of one (instead of 0.2). In this
system our original 12 character bar is 12*5 = 60 units long. Any length can be represented
1
0
0
0
1
0
0
0
1
0
0
0
1
0
0
0
1
0
0
0
1
0
0
0
1
0
0
0
1
0
0
0
by a combination of ‘full characters’ which contain 5 bars each, followed by a terminal
character containing less than 5 bars. For example, a bar graph of length 27 will be 5 full
characters (5*5=25), followed by a character containing the last 2 bars:
Bar of 27 units =
5 Filled Characters +
1 Partially Filled
Character
We can calculate the number of full characters by integer division: length/5. And the
number of bars in the nal, partially lled character is just the remainder: length % 5. A
function for writing the horizontal bar sends the required number of solid -lled characters, ly
then a single, partially-lled character. Assume that the symbols have previously been
loaded into the character-generator RAM at positions 0 through 4.
def DrawHBar(row,length):
fullChars = length / 5
bars = length % 5
GotoXY(row,0) #start at beginning of row
for count in range(fullChars): #full characters sent first
SendByte(4,True)
if bars>0: #final, partially filled character
SendByte(bars-1,True)
The call to SendByte(4,True) sends the fourth symbol in CG-RAM, which is the 5-bar (lled)
character.
4 ANIMATED HORIZONTAL BAR GRAPHS )
The graphs are nice, and fun to watch a few times. But looking at fat lines gets dull after a
while. Let’s spice them up a bit, and add some animation like we did in part 3 with the
‘battery charging’ symbol.
To animate the graph, we need two key functions: one to increment the graph length, and
one to decrement it. Then animation becomes the simple task of keeping track of how
many increments/decrements to do. Using a top-down approach, lets write this function
rst, and worry about the increment/decrement later.
def AnimatedHBar(row,startCol,newLength,oldLength=0):
diff = newLength - oldLength
for count in range(abs(diff)):
if diff>0:
IncrementHBar(row,startCol,oldLength)
oldLength +=1
else:
DecrementHBar(row,startCol,oldLength)
oldLength -=1


Produktspezifikationen

Marke: Joy-it
Kategorie: Spielzeug
Modell: RB-LCD-16x2

Brauchst du Hilfe?

Wenn Sie Hilfe mit Joy-it RB-LCD-16x2 benötigen, stellen Sie unten eine Frage und andere Benutzer werden Ihnen antworten




Bedienungsanleitung Spielzeug Joy-it

Bedienungsanleitung Spielzeug

Neueste Bedienungsanleitung fĂŒr -Kategorien-