Examples > TFT
This example demonstrates how to draw text on the Arduino GLCD screen when connected to an Arduino. The Arduino reads the value of an analog sensor attached to pin A0, and writes the value to the LCD screen, updating every quarter second.
Connect power and ground to the breadboard.
Show me how to do thatShow me how to do that
Place the potentiometer on the breadboard. Connect one side to ground, and the other to power. Connect the middle pin to A0.
Show me how to do thatShow me how to do that
Connect the screen to the breadboard. The headers on the side of the screen with the small blue tab and arrow should be the ones that attach to the board. Pay attention to the orientation of the screen, in these images, it is upside down.
Show me how to do thatShow me how to do that
Connect the BL and +5V pins to power, and GND to ground. Connect CS-LD to pin 10, DC to pin 9, RESET to pin 8, MOSI to pin 11, and SCK to pin 13. If you're using a Leonardo, you'll be using different pins. see the getting started page for more details.
Show me how to do thatShow me how to do that
To use the screen you must first include the SPI and TFT libraries.
Define the pins you're going to use for controlling the screen, and create an instance of the TFT library named TFTscreen
. You'll reference that object whenever you're working with the screen.
To update the screen with text, you'll need to store dynamic content in a char array.
char sensorPrintout[4];
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 "Sensor Value :". 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 sensor values stand out.
In loop()
, read the value from the potentiometer and store 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 potentiometer), and print it to the screen below the static text.
Wait a quarter of a second, then erase the text you just wrote, so you can update it in the next run through loop()
.
The complete sketch is below :