Professional Documents
Culture Documents
This library makes it easy to use a Graphical LCD (GLCD) with Arduino. This is an extensive modi ication o the ks!"!# library that has hi$her per ormance% more eatures% supports more Arduino boards and is easier to inte$rate with di erent panels. &ketches written or the old library should work with little or no modi ication. The con i$uration mechanism has been chan$ed to acilitate use with a broad ran$e o GLCD chips and ATme$a controllers. &ee the section on sketch mi$ration or details on modi ications or the new library. Table o Contents' GLCD Graphical LCD library Wiring and Configuration: Configuration Troubleshooting Using fonts Using bitmaps Migrating your sketch from ks0108 to the new !C" Methods: "rawing #unctions Te$t #unctions
!C" library
backli$ht. The datasheet or your panel provides speci ic in ormation on the wirin$ and choice o components or this. The table below shows common pinouts or )&!"!# panels. The numbers under the Arduino column are the Arduino pins used in the con i$uration ile provided in the download% i you alter the wirin$ to Arduino pins then you must chan$e the pin assi$nments in the con i$uration ile. The numbers in the (anel A636C columns are the pin numbers o the GLCD display panel
Arduino pins 5V Gnd n/a 5V Gnd n/a 5V Gnd n/a 5V Gnd n/a Mega Sanguino Teensy Teensy ++ 5V Gnd n/a Function +5 volts GND Contrast in Panel Panel Panel A 1 2 3 B 2 1 3 C 13 14 12
Wiper of contrast pot
Comments
22 23
0 1 2 3 4 5 ! 7 24 25
0 1 2 3 13 14 15 4 7 8
10 11 12 13 14 15 1! 17 18 1
4 5 ! 7 8
7 8
1 2 3
24 25 2! 27 28 2 33 34
10 11 12
4 5 ! 7 8 15 1! 18 10 11
C(ip 1 select C(ip 2 select Connect to reset )ead/+rite Data/,nstr-ction ")%$
10 11 12 13 14 15 1!
13 14 15 1! 17 5 4
35 3!
2! 27
! 5
)*W D*,
18 "alo# 4$ n/a
37 n/a
28 n/a n/a
7 n/a
17 18
! 18 17
n/a
n/a
n/a
n/a
n/a
0ac/li#(t +5
%ee datas(eet
Gnd
Gnd
Gnd
Gnd
Gnd
0ac/li#(t Gnd
20
20
20
%ee datas(eet
KS-0108 Pin Connections Table (see your datasheet). The ollowin$ illustrations show the wirin$ or these panel types with a standard Arduino ("7#62,#). Althou$h the pin number on the GLCD panels are di erent% the correspondin$ unctions are connected to the same Arduino pins in all three examples so the supplied ks!"!#8Con i$.h con i$uration ile should work without chan$e i you wire your panel ollowin$ the appropriate dia$ram. The ks!"!# datasheet says the reset pin should be taken low or a brie period a ter power is applied. The dia$rams show the display9s reset pin connected to the Arduino reset pin and this will automatically reset the display when the Arduino resets. :ou can also wire the display reset pin to a spare Arduino pin and control reset in so tware by addin$ a de ine to the panel con i$uration ile (see the con i$uration section below). ;ote that some panels may unction correctly without re0uirin$ an external reset< in that case you should connect the panel reset pin to =+volts. 'ote: The diagrams that follow are for standard (rduino boards )(Tmega 1*8+,-8./ 0f you ha1e a different board then you should follow the pin assignments in the 2in Connections Table abo1e/ &ee the datasheet for your panel for the 1alue of the backlight resistor if one is re3uired/
&4"15-0 The &*D"+,! uses di erent timin$ and command pins then the )&!"!# and the most common panels have ewer pixels. The distribution contains a $eneric con i$uration ile named sed"+,!8Con i$.h and an example called /odvk+","8Con i$.h or the 1)+"," panel. >ere is the wirin$ or a typical &*D"+,! (anel'
A tip or makin$ the physical connections is use a small piece o stripboard with header pins or +1% Ground and ?eset. The picture has an example layout or a type 9A9 panel.
/e$a% &an$uino and Teensy boards can provide aster per ormance by allowin$ all the data pins to be connected to the same port (actual per ormance will vary dependin$ on the panel). 'ote that each board type uses a different selection of pins.
Configuration
. you are usin$ a standard Arduino board ("7#62,#) or a /e$a% &an$uino% Teensy% or Teensy==< and you have a ",#x7@ )&A!"!# panel wired accordin$ to the pin connections table above% you don9t need to make any chan$es to con i$uration iles. . you use di erent wirin$ or use a di erent panel type you will need to modi y one o the supplied con i$urations or you can create your own. These con i$uration iles set the panel parameters (display hei$ht% and width% timin$% etc) to match your hardware and allows selection o the Arduino pins used to connect to the display. Althou$h display panel timin$ can also be easily con i$ured% most displays will work without re0uirin$ a con i$uration chan$e or timin$. >owever% you should check the datasheet or your panel to veri y the timin$ values in the panel con i$uration ile. The active con i$uration when the sketch is compiled is selected in a master con i$uration ile named glcd_Config.h. The de ault con i$uration ile (named Bconfig/ks0108_Panel.hB) is or ",#x7@ ks!"!# type panel. The panel con i$uration ile namin$ is' B{PANELNAME}_Panel.hB Chere' {PANELNAME} is the $lcd panel type. ( or example% ks!"!#) GLCD 1ersion 2 (3eta) 4un 5 ,!"!
The panel con i$uration ile includes a board speci ic con i$uration ile that speci ies the pins used or each speci ic board type. The pin con i$uration ile namin$ is a ollows' BDPANELNAME}_{BOA !NAME}.hB {PANELNAME} is the $lcd panel type. ( or example% ks!"!#) {BOA !NAME} is the name o the board (as selected in the Arduino .D*). Eor example% the ks!"!# pin con i$uration ile name or a standard Arduino board is' Bks0108_A"d#ino.hB The e0uivalent ile or the B/e$aB board is' Bks0108_Mega.hB . you chan$e the active con i$uration in the master con i$uration ile $lcd8Con i$.h% make sure that one and only one con i$uration ile is included. (rocessor type is automatically determined rom the board selected when the sketch is built% this allows Arduino style pin numbers to be mapped to ast direct port .F used by the library. (in numberin$ or the ollowin$ processor types are supported' A &tandard Arduino (ATme$a#%"7#%2,#) A /e$a(ATme$a",#!) A &an$uino (ATme$a7@@() A Teensy and Teensy== (AT5!G&37@7% AT5!G&3",#7% ATme$a2,G@) 0n summary: $lcd8Con i$.h includes a panel ile Bconfig/{PANELNAME}_Panel.hB (the active con i$uration) that in turn includes a board speci ic pin mappin$ ile based on arduino board type% Bconfig/{PANELNAME}_{BOA !NAME}.hB !C"diags GLCDdia$s is a test sketch included in the examples older. .t will validate the connections and test the memory o GLCD module as well as report the active con i$uration in ormation to the serial port. . your display is not workin$ properly then check the in ormation displayed in the serial monitor. The sketch prints the in ormation the library is usin$ to the serial monitor and you can use this to veri y i the sketch is con i$ured correctly.
Troubleshooting
;o pixels visible on the display ICheck =+v and Gnd connections between Arduino and GLCD panel ICheck all data and command pins are wired accordin$ to the datasheet and matchin$ the con i$uration settin$s J this is the most common cure to this problem. ICheck the datasheet or your panel to veri y appropriate timin$ values are set in the con i$uration ile. ICheck contrast volta$e (typically between A2 and A@ volts) on contrastAin pin o LCD panel. Chile the sketch is operatin$% try $radually adKustin$ the pot throu$h its ran$e. &ome displays are very sensitive to this settin$. ICheck that sketch has compiled correctly and has downloaded to Arduino. I?un GLCDdia$s test sketch% see Con i$uration section above. Le t and ri$ht side o ima$e reversed I&wap C&*L" and C&*L, wires (or swap pin assi$nments in the con i$uration ile) Display $arbled ICheck all data and command pins are wired correctly and that these match the settin$ in the con i$uration ile. ICheck the datasheet or your panel to veri y appropriate timin$ values are set in the con i$uration ile.
Using fonts
There is a ree Kava application available that can convert (C onts or use with this library. The so tware is called EontCreator, and it can produce a header ile that can be included in your sketch. The header iles should be placed in the directory named onts and included in your sketch. Eor example% i you create a ont named my ont in a header named my ont.h then copy my ont.h to the onts directory and in your sketch' $incl#de (fon)s/*+fon).h( // s+s)e* fon) To use the ont in your sketch you select the ont as ollows' ,LC!.%elec)-on).*+fon)/0 // #se *+fon) ;ote that the distribution contains a ile named allEonts.h that includes all the distributed onts% so you can include these iles instead o explicitly includin$ the individual onts $incl#de (fon)s/all-on)s.h( // all dis)"i1#)ed fon)s Eont de initions are stored in pro$ram memory and this can be si$ni icant or lar$er onts. The L pixel hi$h system ont uses under +!! bytes% the supplied Arial"@ ont uses ",!! bytes o pro$ram memory
Using bitmaps
:ou can use the distributed bitmaps or create your own. The distribution contains a ile named all3itmaps.h that includes all the distributed bitmaps% so you can include this to make the bitmaps available' GLCD 1ersion 2 (3eta) 4un 5 ,!"!
$incl#de (1i)*a2s/allBi)*a2s.h(
;ote that included bitmaps will not consume any memory i they are not explicitly re erenced in your sketch with the Drw3itmap unction. :ou can also display your own ima$es in your sketch. A utility named $lcd/ake3itmap converts a $i % Kp$% bmp% t$a or pn$ ile to a header ile that can be read by the $lcd library. $lcd/ake3itmap.pde is a sketch that can be run usin$ the (rocessin$ environment (its in the bitmaps6utils6$lcd/ake3itmap directory. Eor more in ormation on (rocessin$% see' http'66processin$.or$6 There is a Kava runtime ile ($lcd/ake3itmap.Kar) and Kava source ($lcd/ake3itmap.Kava) in thee bitmaps6utils64ava directory ?un the utility by loadin$ the pde into (rocessin$ (or click on the Kar ile) and dra$ and drop the ima$e ile to be converted into the window.
$lcd/ake3itmap window a ter droppin$ an ima$e named arduino.con. . the ima$e can be converted% a header ile is created in the bitmap directory. Eor example% i the ima$e ile name to be converted is named ima$e.bmp% the header is named ima$e.h Add the ollowin$ line to the sketch' $incl#de (1i)*a2s/i*age.h( and display the ima$e usin$ the ollowin$ code' ,LC!.!"a3Bi)*a2.i*age4 54 +/0 where x and y are the desired location o the upper le t ed$e o the bitmap. .ma$es are stored in pro$ram memory% a ",#x7@ pixel ima$e takes "k bytes o lash. 3ear in mind that each di erent ima$e used in a sketch will reduce the amount o code available to a sketch. $lcd/ake3itmap displays the amount o memory re0uired or the ima$e and other use ul in ormation when it does the conversion.
!C" library
The GLCD library is an extensive modi ication o the ks!"!# library. .t now supports more chips and is easier to inte$rate with di erent panels. The $raphical unctions are backwards compatible (except where noted) so existin$ sketches should work with little or no modi ication to the code. The con i$uration mechanism has been chan$ed to acilitate use with a broad ran$e o GLCD chips and ATme$a controllers. . your wirin$ does not match the de ault pin
assi$nments you will need to need to modi y the con i$uration iles in the new library to match your wirin$. The distribution includes the system ont and arial"@ onts that were distributed with the previous version% but these are now in a subdirectory called M onts9 so you will need to modi y the include statement' chan$e $incl#de (%+s)e*-on)657.h( // s+s)e* fon) to $incl#de (fon)s/%+s)e*-on)657.h( // s+s)e* fon) 3itmaps are now in a bitmaps subdirectory and the ile names include the width and hei$ht< so chan$e ' Hinclude BArduino.con.hB 66 the bitmap distributed with the ks!"!# lib To $incl#de (1i)*a2s/A"d#ino&con89589.h( // 89589 1i)*a2 The Arduino.con.h bitmap ile was renamed to Arduino.con7@x7@.h to di erentiate it rom other si-e bitmaps supplied or panels o di erent pixel dimensions. . you are usin$ any o the ollowin$ unctions you should either chan$e the code use the new unction or include $lcd8Deprecated.h ile that will convert the old unction name to the new unction. Draw1ertLine(x% y% len$th% color) is now' Draw1Line(x% y% len$th% color) Draw>oriLine(x% y% len$th% color) is now ' Draw>Line(x% y% len$th% color) Clear&ysTextLine(row) is now *raseTextLine(row) The character output unctions behave di erently in the new library. The new library now sets or clears all pixels o a ont ($lyph)% the old library did not consistently erase pixels in the whitespace below the $lyph. This means that i there are $raphics very close below the character they may be overwritten with the new text ouput code. The workaround is to either move the $raphics obKects so they are not cleared when the text is written or to draw the $raphical obKects a ter the text is displayed. Another chan$e is the way a strin$ wraps on the newline character. The old library wrapped to the column where the strin$ started% the new library now wraps to the be$innin$ o the text area. &ee the section on Text Areas to see how you can use this new capability to control where text will wrap on the display. &ee the section on Con i$uration or details on the new con i$uration iles. :ou can use the same wirin$ as the old library but the con i$uration ile ormat has chan$ed. The ks!"!#8Con i$%h ile included in the distribution uses exactly the same pins as the ks!"!#8Arduino.h ile supplied with the old library% but i you chan$ed the Arduino pin numbers you will need to modi y ks!"!#8Con i$ to match your wirin$.
!C" Methods:
>ere is a summary o the methods supported by this library. ;ote that all coordinates start rom ! unless otherwise noted. !%! is the pixel on the upper le t ed$e o the screen Table o contents GLCD Graphical LCD library Wiring and Configuration: Configuration A1? port and pin numbers Troubleshooting Using fonts Using bitmaps Migrating your sketch from ks0108 to the new !C" Methods: .nit() &etDisplay/ode() Clear&creen() ?eadData() CriteData() "rawing #unctions Coordinate system (roperties Colors GotoN:() &etDot() Draw1Line() Draw>Line() DrawLine() Draw?ect() Eill?ect() .nvert?ect() Draw?ound?ect() DrawCircle EillCircle() Draw3itmap() Te$t #unctions &electEont() &etEontColor() &etText/ode() ClearArea() *raseTextLine(row) *raseTextLine() CursorToN:() Arduino print unctions
!C" library
Text Areas De ineArea() *nhanced print unctions printElash () printElashln () (rint () (rint 8( () CharCidth() &trin$Cidth() &trin$Cidth8(() Le$acy text output unctions (utChar() (uts() (rint;umber() (uts8(()
Init()
Description' This should be called in setup to initiali-e the library prior to callin$ any other unction. The display is cleared and ready or use a ter callin$ .nit. &yntax GLCD..nit() < 66 initiali-e the library to draw dark pixels on a li$ht back$round GLCD..nit(;F;A.;1*?T*D) < 66 same as above GLCD..nit(.;1*?T*D) < 66 initiali-e the library to draw li$ht pixels on a dark back$round (arameters .nit with no parameter is the standard initiali-ation% this is identical to' .nit(;F;A .;1*?T*D) .nit(.;1*?T*D) will invert dark and li$ht pixels when drawn
SetDisplayMode()
Description' sets the $raphical state to normal (3LAC) colored pixels are dark)% or inverted (C>.T* colored pixels are dark) &yntax GLCD.&etDisplay/ode(;F;8.;1*?T*D)< 66 sets the state to normal GLCD.&etDisplay/ode(.;1*?T*D)< 66 sets the state to inverted (;ote this unction was named &et.nverted() in the previous library releases)
ClearScreen()
Description' *rases all screen pixels (pixels rom !%! to GLCD.CidthA"%GLCD.>ei$htA ") &yntax GLCD.Clear&creen()< 66 sets all pixels to C>.T* (i ;F?/AL mode or 3LAC) i .;1*?T*D) GLCD.Clear&creen(C>.T*)< 66 same as above GLCD.Clear&creen( 3LAC))< 66 clears screen writin$ 3LAC) pixels ;ote' . the display is in .;1*?T*D mode% then the color C>.T* will paint the screen 3LAC) and the color 3LAC) will paint the screen C>.T*.
ReadData()
Description' ?eturns the data byte at the current x%y location &yntax' GLCD.?eadData()< &ee also' GotoN:()< 66 return the byte o data at the current x%y location
WriteData()
Description' Crites the $iven byte o data at the current x%y location &yntax' GLCD.CriteData( data)<
"rawing #unctions
Coordinate system
!%! is the upper le t ed$e o the display. GLCD.Cidth is the width o the display in pixels GLCD.hei$ht is the hei$ht o the display in pixels GLCD.?i$ht is the ri$htAmost pixel (e0uals GLCD.CidthA") GLCD.3ottom is the bottom pixel (e0uals GLCD.>ei$htA") GLCD.CenterN is the hori-ontal center (e0uals GLCD.Cidth6,) GLCD.Center: is the vertical center (e0uals GLCD.>ei$ht6,)
roperties
GLCD.Cidth A the display width in pixels GLCD.>ei$h A the display hei$ht in pixels GLCD.?i$ht A the display width A" GLCD.3ottom A the display hei$ht A" GLCD.CenterN A hal o the display width GLCD.Center:A hal o the display hei$ht
Colors
Two colors are supported in this version. 3LAC) is a dark pixel% C>.T* is a pixel that is not dark 3LAC) is the de ault color
Goto!"()
Description' moves the $raphics cursor to the $iven x%y coordinates. &yntax GLCD.GotoN:(x%y)< (arameters x J a value rom ! to GLCD.CidthA" y A a value ron ! to GLCD.>ei$htA"
SetDot()
Description' sets the pixel at the $iven x%y coordinate to the $iven color &yntax GLCD.&etDot(x%y% 3LAC))< 66 draws a 3LAC) pixel at x%y GLCD.&etDot(x%y% C>.T*)< 66 erases the pixel at x%y (arameters x J a value rom ! to GLCD.CidthA" y A a value ron ! to GLCD.>ei$htA"
Dra#VLine()
Description' Draws a vertical line &yntax GLCD.Draw1ertLine(x% y% hei$ht)< 66 draws a 3LAC) line rom x%y to x% y = hei$ht GLCD.Draw1ertLine(x% y% hei$ht% 3LAC))< 66 as above GLCD.Draw1ertLine(x% y% hei$ht% C>.T*)< 66 as above but the pixels on the line are erased
(arameters x J a value rom ! to GLCD.CidthA" y A a value rom ! to GLCD.>ei$htA" hei$ht J a value rom " to GLCD.>ei$htAyA" 3LAC) or C>.T* is an optional parameter indicatin$ pixel color% de ault is 3LAC) (;ote this unction was named Draw1ertLine() in the previous library releases)
Dra#$Line()
Description' Draws a hori-ontal lines &yntax GLCD.Draw>oriLine(x% y% width)< 66 draws a 3LAC) line rom x%y to x = width % y GLCD.Draw>oriLine(x% y% width% 3LAC))< 66 as above GLCD.Draw>oriLine(x% y% width% C>.T*)< 66 as above but the pixels on the line are erased (arameters x J a value rom ! to GLCD.CidthA" y A a value rom ! to GLCD.>ei$htA" width J a value rom " to GLCD.CidthAxA" 3LAC) or C>.T* is an optional parameter indicatin$ pixel color% de ault is 3LAC) (;ote this unction was named Draw>oriLine() in the previous library releases)
Dra#Line()
Description' Draws a line between two coordinates. &yntax GLCD.DrawLine( x"% y"% x,% y,< 66 draws a 3LAC) line rom x"%y" to x,%y, GLCD.DrawLine( x"% y"% x,% y,% 3LAC))< 66 as above GLCD.DrawLine( x"% y"% x,% y,% C>.T*)< 66 as above but the pixels on the line are erased (arameters x" J a value rom ! to GLCD.CidthA" indicatin$ start x coordinate y" A a value ron ! to GLCD.>ei$htA" indicatin$ start y coordinate x, J a value rom ! to GLCD.CidthA" indicatin$ end x coordinate y, A a value ron ! to GLCD.>ei$htA" indicatin$ end y coordinate 3LAC) or C>.T* are optional parameters speci yin$ pixel color% de ault is 3LAC)
Dra#Rect()
Description' Draws a rectan$le o $iven width and hei$ht x%y is the upper le t ed$e o the rectan$le The lower ri$ht ed$e is at x=width% y=hei$ht ;ote that the len$th o the hori-ontal sides will be width=" pixels% the vertical sides will be hei$ht=" pixels &yntax GLCD.Draw?ect( x% y% width% hei$ht)< width and hei$ht startin$ at x%y GLCD.Draw?ect( x% y% width% hei$ht% 3LAC))< GLCD.Draw?ect( x% y% width% hei$ht% C>.T*)< are erased 66 draws a 3LAC) rectan$le o $iven 66 as above 66 as above but the rectan$le pixels
(arameters x% y J the x%y coordinates o the rectan$le to be drawn width% hei$ht J the width and hei$ht o the rectan$le
%illRect()
Description' Eills the interior o a rectan$le speci ied by a pair o coordinates% a width% and a hei$ht. The le t and ri$ht ed$es o the rectan$le are at 5 and 5 : 3id)h ; 1. The top and bottom ed$es are at + and + : heigh) ; 1. The resultin$ rectan$le covers an area 3id)h pixels wide by heigh) pixels tall startin$ rom the pixel at x%y. The rectan$le is illed usin$ the $iven color (3LAC) i none $iven) (;ote that Eill?ect behavior has chan$ed rom the previous versions o the library. The illed rectan$le will be one pixel smaller in width and hei$ht than the old version. This chan$e was to make the unctionality consistent with the way 4ava and CH create illed rectan$les) &yntax GLCD.Eill?ect( x% y% width% hei$ht)< GLCD.Eill?ect( x% y% width% hei$ht% 3LAC))< GLCD.Eill?ect( x% y% width% hei$ht% C>.T*)< erased
In&ertRect()
Description' &ets 3LAC) pixels C>.T* and C>.T* pixels 3LAC) within the $iven rectan$ular area. The le t and ri$ht ed$es o the inverted area are at 5 and 5 : 3id)h ; 1. The top and bottom ed$es are at + and + : heigh) < 1 GLCD 1ersion 2 (3eta) 4un 5 ,!"!
&yntax GLCD..nvert?ect( x% y% width% hei$ht)< (arameters As Eill?ect but without the color parameter
Dra#RoundRect()
Description' Draws a rectan$le with rounded corners &yntax GLCD.Draw?ound?ect( x% y% width% hei$ht% radius)< 66 draws a 3LAC) rectan$le similar to Draw?ect but with corners o the $iven radius GLCD.Draw?ound?ect( x% y% width% hei$ht% radius% 3LAC))< 66 as above GLCD.Draw?ound?ect( x% y% width% hei$ht% radius% C>.T*)< 66 as above but the rectan$le pixels are erased (arameters x%y%width%hei$ht as Draw?ectan$le radiusA a value rom " to hal the hei$ht or width o the rectan$le
Dra#Circle
Description' Draws a circle centered at x%y with the $iven radius The circle will it inside a rectan$ular area bounded by xAradius%yAradius and x=radius%y=radius ;ote that because the circle is drawn rom the center pixel out% the diameter will be , O radius =" pixels. &yntax GLCD.DrawCircle( x% y% r)< 66 draws a 3LAC) circle centered at x%y with radius r GLCD.DrawCircle( x% y% r% 3LAC))< 66 as above GLCD.DrawCircle( x% y% r% C>.T*)< 66 draws a C>.T* circle centered at x%y with radius r (arameters x J a value rom ! to GLCD.?i$ht (GLCD.CidthA") y A a value ron ! to GLCD.3ottom (GLCD.>ei$htA") radiusA a value rom " to hal the hei$ht or width o the rectan$le
%illCircle()
Description' Draws a illed in circle centered at x%y with the $iven radius &yntax and (arameters GLCD 1ersion 2 (3eta) 4un 5 ,!"!
see DrawCircle
Dra#'itmap()
Description' Draws a bitmap ima$e with the upper le t ed$e at the x%y coordinates. 3itmap data is in pro$ram memory (Elash) A utility or creatin$ bitmap header iles% $lcd/ake3imtap% is supplied with the download &yntax GLCD.Draw3itmap(Obitmap% x% y)< GLCD.Draw3itmap(Obitmap% x% y% 3LAC))< 66 as above GLCD.Draw3itmap(Obitmap% x% y% C>.T*)< 66 inverts pixels
Te$t #unctions
Select%ont()
Description' &elects the ont de inition as the current ont. &ubse0uent printin$ unctions will use this ont. Eont de initions are stored in pro$ram memory. :ou can have as many onts de ines as will it in pro$ram memory and can switch between them with this unction. &yntax GLCD.&electEont( ont) < 66 ont is a ont pointer de ined in a ont de inition ile. Futput is rendered usin$ dark pixels. GLCD.&electEont( ont% 3LAC)) 66 as above GLCD.&electEont( ont% C>.T*) 66 printed output rendered as C>.T* pixels
Set%ontColor()
Description' &ets the color o the currently selected ont. &yntax GLCD.&etEontColor( 3LAC)) 66 printed output rendered as 3LAC) pixels GLCD.&etEontColor( C>.T*) 66 printed output rendered as C>.T* pixels GLCD.&etText/ode() Description' 66 &ets the $iven text mode (currently only scroll direction is supported) &yntax GLCD.&etText/ode(&C?FLL8G() 66 normal scroll direction% old lines scroll up GLCD.&etText/ode(&C?FLL8DFC;) 66 reverse scroll direction% old lines scroll down
Set(e)tMode()
Description' 66 &ets the $iven text mode (currently only scroll direction is supported) &yntax GLCD.&etText/ode(&C?FLL8G() 66 normal scroll direction% old lines scroll up GLCD.&etText/ode(&C?FLL8DFC;) 66 reverse scroll direction% old lines scroll down
ClearArea()
Description' clears the current text area usin$ the current ont back$round color. The cursor is set to the upper le t corner. &yntax GLCD.ClearArea()< 66 clears the text area and sets the cursor to the upper le t corner o the text area
*rase(e)tLine(ro#)
Description' clears all text on the $iven row within the text area% moves the cursor to the le t position.
*rase(e)tLine()
Description' clears text on the current line% de ault is to clear rom the cursor to the end o the text area &yntax GLCD.*raseTextLine()< GLCD.*raseTextLine(eraseTF8*FL)< GLCD.*raseTextLine(eraseE?F/83FL)< GLCD.*raseTextLine(eraseEGLL8L.;*)< 66 erase rom cursor to end o line 66 as above 66 erase rom be$innin$ o line to cursor 66 erase the entire line
Cursor(o()
Description' move the cursor to the $iven row and column. Chen variable width onts are used% the column calculation uses the width o the widest character. &yntax GLCD.CursorTo( column% row)< 66 ! based coordinates or character columns and rows
Cursor(o!"()
Description' moves the text cursor to the coordinates $iven by x%y relative to the upper le t corner. &yntax GLCD.CursorToN:( x%y)< GLCD 1ersion 2 (3eta) 4un 5 ,!"!
Draw&trin$(str% x% y)< Description' prints the $iven strin$ o characters startin$ rom the $iven x and y coordinates. The coordinates are relative to the text areaA use a text area coverin$ the ull display i you want the x%y parameters to be the same as the coordinates or Graphical unctions like GotoN:. Draw&trin$8(((ro$/em&trin$% x% y)< Description' as above but the strin$ is de ined in (ro$ram memory ( lash)
(e)t Areas
All o the text unctions described above can be applied to a select rectan$ular area o the screen% called a text area.
A text area acts like a virtual terminal and text output is displayed within the con ines o a rectan$le $iven in the De ineArea command. Eor example' $Text textTop R $Text(textAreaTF()< 66 create a text area coverin$ the top hal o the display $Text myTextArea R $Text(GLCD.CenterNA"7% GLCD.Center: A"7% GLCD.CenterN ="7% GLCD.Center:="7)< 66 create a text area coverin$ the center 2, pixels o the display All o the text unctons operate on a text area by usin$ the text area name instead o MGLCD9% or example' textTop.&electEont(&ystem+xL)< 66 select the system ont or the text area name textTop textTop.println(Pa line o textQ)< 66 print a line o text to the text area. &ee the download sketches or more example usa$e. Text Areas are created usin$ one o the three De ine Area methods described below'
De+ineArea()
Description' de ines the rectan$ular area or text output. The rectan$ular area can be speci ied usin$ either' a prede ined area % an area determined by a $iven number o rows and columns o the $iven ont% or a rectan$ular area speci ied by the upper le t and lower ri$ht pixel coordinates. &yntax De ineArea( preDe inedArea% scrollDirection)< 66 create a text area usin$ one o the prede ined values preDe inedArea is one o ' textAreaEGLL% textAreaTF(% textArea3FTTF/% textAreaL*ET% textArea?.G>T% textAreaTF(L*ET%textAreaTF(?.G>T%textArea3FTTF/L*ET%textArea3FTTF/?. G>T. scrollDirection can be &C?FLL8G( or &C?FLL8DFC;% i scrollDir is omitted the direction will be &C?FLL8G(. De ineArea( x"% y"% columns% rows% ont% scrolldirection)< As above but the hei$ht and width o the area is determined by the number o columns and rows or the $iven ont. Eor proportional (variable width) onts% the width o widest character is used. De ineArea( x"% y"% x,% y,% scrolldir)< (or width%hei$ht as you pre er As above but x"% y"% x,% y,% determine the rectan$ular area o the text window
All o the Text unctions listed above can be used with user de ined areas. The ollowin$ ra$ment ( rom the $lcdDemo example sketch) creates a text area in the center o the screen usin$ the Arial8"@ ont that is holds a sin$le character ( one column wide by one row hi$h)' $Text countdownArea R $Text(GLCD.CenterN% GLCD.Center:%"%"%Arial8"@)< 66 declare text area or a sin$le di$it countdownArea.ClearArea()< 66 clear the text area countdownArea.print(count)< 66 print a di$it in the text area
print%lashln ()
Description' As printElash but wraps ollowin$ text to the next line &yntax GLCD.printElashln( strin$)<
rint+ ()
Description' Crites a se0uence o data ormatted as speci ied by the ormat ar$ument. The ormat strin$ uses standard print () ormatin$ S ta$s% but loatin$ point is not supported. &yntax GLCD.(rint ( ormat% ar$uments T)< The ormat strin$ contains text or optional embedded ormat ta$s. The ar$ument list types must match the ormat ta$s. Gsers not already amiliar with usin$ print are advised that the standard Arduino print unctions are simpler to use.
rint+, ()
Description' as (rint above but the ormat strin$ is stored in Elash instead o ?A/ &yntax GLCD.(rint 8(( ormat% ar$uments T)< &ee (rint () GLCD 1ersion 2 (3eta) 4un 5 ,!"!
CharWidth()
Description' returns the width in pixels o the $iven character includin$ any interA character $ap pixels ollowin$ the character when rendered on the display. &yntax byte width R GLCD. CharCidth(c)<
Strin-Width()
Description' returns the width in pixels o the $iven strin$ in the currently selected ont &yntax byte width R GLCD. &trin$Cidth(strin$)<
Strin-Width, ()
Description' returns the width in pixels o the $iven strin$ stored in pro$ram memory &yntax byte width R GLCD. &trin$Cidth8((($m&trrin$)<
utChar()
Description' prints the $iven character at the current cursor position. .t is su$$ested that the Arduino print character unction% GLCD.print(character) is used in new applications J it has identical unctionality with the bene it o similar syntax to other arduino print methods. ;ote that there is a subtle di erence in the way this unction handles the newline character compared to the ks!"!# library. The old (utChar() would treat the newline character Kust like any other character and since many onts donUt don9t have a $lyph de ined or the newline its would be thrown away. The new (utChar() does newline processin$ and will wrap and potentially scroll the text window. &yntax GLCD. (utChar(c)< 66 print the character c at the current cursor position (same as GLCD.print(c)<
uts()
Description' prints the $iven strin$ o characters startin$ rom the current cursor position. ;ote that the old library would process newlines in (uts(). .t would wrap to the text line below the current line but back to the N position where strin$ printin$ started. The new code lets (utChar() process the newlines and so a new line will wrap to the line below but will wrap to the start N position o the text window rather than the N position when the (uts()started. Also% the old (uts() assumed -ero paddin$ below a ont while the new (uts() handles paddin$ consistently across all the unctions. &o the new (uts()6(utchar() will wrap " pixel lower than the old (uts() routine. &yntax GLCD. (uts(strin$)< 66 66 print the strin$ at the current cursor position (same as GLCD.print(strin$)<
rint.umber()
&ee GLCD.print(number)<
uts, ()
Description' prints a strin$ stored in pro$ram memory startin$ orm the current cursor position. &yntax GLCD. (uts8((pro$/em&trin$)< ;ote that the strin$ bein$ printed must already be de ined as a pro$ram memory strin$. &ee also printElash which allocates and prints the strin$ in pro$ram memory