Hardware Reference
In-Depth Information
print the temperature when a change is detected. The comparison is made on
line 80, using an if() statement. If the temperature has changed since the last
reading, in lines 85 through 88 a background color is declared, the stroke color
is changed, and a portion of the screen is erased. Before the text is displayed,
the color is changed back to white.
Text must be supplied as a char array, but it is often much easier to print
text into a String. On line 91 a String object called tempVal is created, stor-
ing the temperature as a String . The next line converts the String into a char
array, storing it into the tempPrintout . This array is printed on the TFT screen
at coordinates that match up with the rectangle you drew earlier.
Finally, the sketch is told to wait for 2 seconds before repeating.
Exercises
The temperature display is visible on the screen, but it could do with being a
little prettier—or maybe even more colorful. Modify the sketch to change either
the foreground or the background of the text according to the temperature; 15
degrees could be a cool blue and 35 a bright red.
Summary
In this chapter, you have seen what a TFT screen is, how it can be used for
your projects, and how an Arduino communicates with it. You have seen how
to initialize the screen, how to print text and pictures to the screen, as well as
basic graphics in black and white and in color. In the next chapter, I will talk
about servo motors and how to control them using an Arduino with just a few
lines of code.
 
Search WWH ::




Custom Search