Examples > TFT

TFT Color Picker

This example for the Arduino TFT screen reads the input of three analog sensors, using the values to change the screen's color.

Color on the TFT screen is handled as 8-bit numbers (0-255). However, the library scales these values to 5-bits (32 levels) for red and blue, 6-bits (64 levels) for green.

Hardware Required

  • Arduino Uno
  • Arduino TFT screen
  • breadboard
  • hookup wire
  • three 10-kilohm potentiometers


Connect power and ground to the breadboard.

Attach the three pots to the breadboard, connecting their outside legs to power and ground. the center legs should connect to A0-A2.

Connect the LCD 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.

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.

Click the image for a larger version


To use the screen you must first include the SPI and TFT libraries.

#include <SPI.h>
#include <TFT.h>

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.

#define cs   10
#define dc   9
#define rst  8  

TFT TFTscreen = TFT(cs, dc, rst);

In setup(), initialize the screen and clear the background. Start serial communication as well.

void setup() {
  TFTscreen.background(255, 255, 255);

In loop(), read the values fron the pots, mapping them to values between 0-255. with background(), set the mapped background colors and print the values to the serial monitor.

void loop() {

  int redVal = map(analogRead(A0), 0, 1023, 0, 255);
  int greenVal = map(analogRead(A1), 0, 1023, 0, 255);
  int blueVal = map(analogRead(A2), 0, 1023, 0, 255);

  TFTscreen.background(redVal, greenVal, blueVal);

  Serial.print(" , ");
  Serial.print(" , ");



The complete sketch is below :

SORRY, There is an error at our code repository, please inform to web@arduino.cc