Examples > TFT
This example for the Arduino TFT screen reads the value of a potentiometer, and graphs it on screen. This is similar to the serial communication Graph example.
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 TFT 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.
Create a variable for holding the position of the x-axis of the graph. You'll increment this each loop()
. In setup()
, initialize the screen and make the background a nice color.
In loop()
, read the value from the potentiometer, and map it to a value that fits in the screen's height.
Set the stroke color to something that will stand out against the nice color you chose for the background, and draw a line from the bottom of the screen based on the value of the sensor
Before closing up loop()
, check to make sure the graph hasn't gone past the edge of the screen. If it has, erase everything, and start back at 0 on the x-axis.
The complete sketch is below :