Examples > TFT
This example for the Esplora with an Arduino TFT screen reads the temperature with the onboard thermisistor, and prints it out on screen.
Attach the TFT screen to the socket on your Esplora, with the label "SD Card" facing up.
To use the screen you must first include the SPI and TFT libraries. Don't forget to include the Esplora library as well.
To update the screen with text, you'll need to store dynamic content in a char array.
char tempPrintout[3];
In setup()
, initialize the screen and clear the background. Set the color for the font with stroke()
, and write any static text to the screen. In this case, you'll write "Degrees in C :". This will stay at the top of the screen and not change as long as the sketch runs. Before entering the loop()
, set the text size so you can really see the temperature stand out.
In loop()
, read the temperature in Celsius with Esplora.readTemperature(DEGREES_C)
, storing it in a string. Convert the string content to a char array, storing it in the global array you declared int he beginning of your program.
Set the text color (this would be a good place to change the color of the text depending on the value from the thermometer), and print it to the screen below the static text.
Wait for one second, then erase the text you just wrote, so you can update it in the next run through loop()
.
The complete sketch is below :