Hardware Reference
In-Depth Information
On line 21, another variable is created, a char array called tempPrintout . This
will be used to store the temperature that will be printed out on the screen.
On line 23, setup() is declared. There are a lot of things to coni gure in this
sketch, so setup() will have a lot of work to do. First, communication with the
screen is started on line 26. In this example, the TFT screen is used for debug
messages, so it must be set up to display any status messages before proceed-
ing. On line 29, stroke() is called, informing the TFT screen of the color that
should be used for future drawing events, including text messages. To make
sure that any text is readable, background() is called, setting the screen to black.
On line 33, the sketch attempts to initialize the SD library. In case of failure,
text() is called with a message at coordinates 0,0. This results in some text
being displayed on the top-left corner of the screen. If the SD library did start,
the next step is to load an image. The sketch looks for a i le called bg.bmp in the
root directory of the SD card. If it i nds the image, it places it into the PImage
object backgroundIMG . The sketch then tests the contents of backgroundIMG for
a valid graphics i le. If the contents are not valid, a text error message displays
on the TFT screen. If the contents are valid, then the background image displays
on the screen starting at coordinates 0,0, the top-left corner. Finally, text size is
set to 5; 50 pixels high.
loop() is declared on line 54. This function begins by reading in the light level
the voltage on pin A3. The analog-to-digital converter returns values varying
from 0 to 1023, but the sketch would like a different value. Ideally, these values
should not exceed 64. The screen is 128 pixels high, and the graph takes up the
lower portion of the screen, so 64 is an excellent maximum. The ideal function
to do this is map() . Next, the sketch needs to print a new line on the graphs, but
before doing that, there is one question that needs answering; has the graph
reached the edge of the screen? This is checked in the if() statement on line
61. If the graph has reached the edge of the screen, several things need to be
done. First, the background image is refreshed, erasing anything present on the
screen. Next, both the stroke and i ll graphics are set to blue. Then, a rectangle
is printed, where the temperature is supposed to go. Finally, the lightPos vari-
able is set to 0, the left side of the screen.
On line 72, a line is drawn on the screen. The i rst set of arguments are the
x and y starting coordinates of the line, and the second set of coordinates is
screen and y -end coordinates of the line. height() and the value from the light
sensor are used to determine the length of the line on the y -axis.
Now that the light level has been calculated and drawn on screen, it is time
to look at the temperature. The analog value of the LM35 is read in, and a
small conversion is made to transform the value into a temperature in Celsius.
Now the sketch checks if the temperature has changed. Erasing a portion of
the screen and printing a new number can cause a visible l icker. Because the
temperature shouldn't vary that much, a simple system has been put in place to
Search WWH ::




Custom Search