EsploraTFTColorPicker

Using the joystick and slider, change the color of the TFT screen.

Esplora TFT Color Picker

This example for the Esplora with an Arduino screen reads the input of the joystick's two axes and the slider, using the values to change the screen's color.

Color on the TFT screen 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 Esplora

  • Arduino TFT screen

Circuit

Esplora GLCDColorPicker

Attach the screen to the socket on your Esplora, with the label "SD Card" facing up.

Code

To use the screen you must first include the SPI and TFT libraries. Don't forget to include the Esplora library as well.

1#include <Esplora.h>
2#include <GLCD.h>
3#include <SPI.h>

In

setup()
, start serial communication so you can read the values used for the background color. Also, start the screen and make the background white.

1void setup() {
2
3 Serial.begin(9600);
4
5 EsploraTFT.begin();
6
7 EsploraTFT.background(255, 255, 255);
8}

In

loop()
, read the values from the joystick axes and slider, mapping them to values between 0-255. with
background()
, set the mapped background colors and print the values to the serial monitor.

1void loop() {
2
3 int xValue = map(Esplora.readJoystickX(), -512, 512, 0, 255);
4
5 int yValue = map(Esplora.readJoystickY(), -512, 512, 0, 255);
6
7 int slider = map(Esplora.readSlider(), 0, 1023, 0, 255);
8
9 EsploraTFT.background(xValue, yValue, slider);
10
11 Serial.print("background(");
12
13 Serial.print(xValue);
14
15 Serial.print(" , ");
16
17 Serial.print(yValue);
18
19 Serial.print(" , ");
20
21 Serial.print(slider);
22
23 Serial.println(")");
24
25 delay(33);
26
27}

The complete sketch is below :

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

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.

Suggest Changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. You can read more on how to contribute in the contribution policy.