Hardware Reference
In-Depth Information
Listing 13-1 continued
60 // Have we reached the edge of the screen?
61 if (lightPos == 160)
62 {
63 screen.image(backgroundIMG, 0, 0);
64 screen.stroke(0, 0, 255);
65 screen.fill(0, 0, 255);
66 screen.rect(100, 0, 60, 50);
67 lightPos = 0;
68 }
69
70 // Set up line color, and draw a line
71 screen.stroke(127, 255, 255);
72 screen.line(lightPos, screen.height() - lightLevel,
73 lightPos, screen.height());
74 lightPos++;
75 // Get the temperature
76 int tempReading = analogRead(A2);
77 int tempC = tempReading / 9.31;
78
79 // Has the temperature reading changed?
80 if (tempC != currentTemp)
81 {
82 // Need to erase previous text
83 screen.stroke(0, 0, 255);
84 screen.fill(0, 0, 255);
85 screen.rect(100, 0, 60, 50);
86
87 // Set the font color
88 screen.stroke(255, 255, 255);
89
90 // Convert the reading to a char array, and print it
91 String tempVal = String(tempC);
92 tempVal.toCharArray(tempPrintout, 4);
93 screen.text(tempPrintout, 120, 5);
94
95 // Update the temperature
96 currentTemp = tempC;
97 }
98
99 // Wait for a moment
100 delay(2000);
101 }
On the i rst few lines of the sketch, you import the libraries that will be
required for this project: the TFT library for the LCD screen, the SD library for
the SD card reader, and the SPI library, which is required for communication
by the other libraries.
On the following lines, some pin declarations are made; these are the pins
that will be used for the TFT screen. RST is the reset pin that will be used to
Search WWH ::




Custom Search