Next, you will need to download
the Arduino IDE. To do this, visit
the official Arduino website
( www.arduino.cc) and click the
Download link at the top of the page.
(The following instructions are for
Windows users.) Click on the
Windows Installer link and run the
installation program. This will cause
the Arduino IDE to be installed in the
C:\Program Files (x86)\Arduino
folder.
Now, download both of the
Touch Shield V2.0 libraries. Visit each
link in Table 2 with your web
browser, and click the Download ZIP
button on each page. Open each of
the ZIP archives and unzip all of the
contents into the C:\Program Files
(x86)\Arduino\libraries folder.
Because of a quirk in the way the
Arduino IDE imports libraries, you
will need to rename both of the
folders you just created. Rename the
TFT_Touch_Shield_V2-master folder
to TFTscreen; rename the
Touch_Screen_Driver-master folder to
TFTtouch.
As you can see from the
screenshots in Figures 1 and 2, the
touchscreen LCD display was
designed to be used in portrait mode
(240x320) instead of landscape
mode. As near as I can tell, there
doesn’t seem to be any way to
change the orientation, so you need
to take this into consideration when
designing games for this display. I
mainly used font sizes 2, 3, and 4.
Font size 1 is pretty much useless
because the characters are so small
they are virtually unreadable.
Although finger pressure detection is
very good on the touchscreen, I
would recommend that you use a
stylus because it is more precise and
it obscures the screen less than a
person’s finger. This can be a factor
in playing some of the games.
Let’s look at the code for the
sliding puzzle game which is shown
in Table 3. You will notice that the
variable declarations appear at the
top of the program. There are two
main sections in Arduino code: the
“setup” block and the “loop” block.
The setup block is meant to hold
code that is executed only once. The
code in the loop block is executed
over and over again.
After the loop block, I put the
custom functions that were used to
handle specific tasks. In the “setup”
block, I wrote some code that draws
the playing grid for the puzzle game
using the library functions provided
by Seeed Studio.
In your program code, each
screen function name should be
preceded by the “Tft” library object
name. For example,
Tft.fillScreen(0,239,0,319,BLUE);
would fill the entire screen with the
color blue. Here are some more
examples:
Tft.drawLine(unsigned int x0,unsigned
int y0,unsigned int x1,unsigned int
y1,unsigned int color);
Draws a line from the upper-left
point (x0,y0) to the lower-right point
(x1,y1) using the specified color.
Tft.drawRectangle(INT16U poX,
May 2014 43
FIGURE 1. FIGURE 2.
Post comments on this article and find any associated files and/or downloads at www.nutsvolts.com/
index.php?/magazine/article/may2014_Spencer.