Programming Arduino Getting Started with Sketches


Figure 9-1 An Alphanumeric LCD shield Figure 9-2



Yüklə 5,42 Kb.
Pdf görüntüsü
səhifə64/78
tarix22.12.2023
ölçüsü5,42 Kb.
#189286
1   ...   60   61   62   63   64   65   66   67   ...   78
Arduino SimonMonk 2011

Figure 9-1
An Alphanumeric LCD shield


Figure 9-2
LCD shield attached to an Arduino board
A USB Message Board
For a simple example of a simple use of the display, we are going to make a USB message
board. This will display messages sent from the Serial Monitor.
The Arduino IDE comes with an LCD library. This greatly simplifies the process of
using an LCD display. The library gives you useful functions that you can call:
• clear
clears the display of any text.
• setCursor
sets the position in row and column where the next thing that you print will
appear.
• print
writes a string at that position.
This example is listed in sketch 9-01:


As with all Arduino libraries, you have to start by including the library to make the
compiler aware of it.
The next line defines which Arduino pins are used by the shield and for what purpose.
If you are using a different shield, then you may well find that the pin allocations are
different, so check in the documentation for the shield.
In this case, the six pins used to control the display are D4, D5, D6, D7, D8, and D9.


The purpose of each of these pins is described in 
Table 9-1
.
Table 9-1
LCD shield pin assignments
The 
setup
function is straightforward. You start serial communications so that the Serial
Monitor can send commands and initialize the LCD library with the dimensions of the
display being used. You also display the message “Arduino Rules” on two lines by setting
the cursor to top-left, printing “Arduino,” then moving the cursor to the start of the second
row and printing “Rules.”
Most of the action takes place in the 
loop
function, which checks for any incoming
characters from the Serial Monitor. The sketch deals with characters one at a time.
Apart from ordinary characters that the sketch will simply display, there are also a
couple of special characters. If the character is a 

Yüklə 5,42 Kb.

Dostları ilə paylaş:
1   ...   60   61   62   63   64   65   66   67   ...   78




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin