Example Code of Refreshing Color for Arduino
Last revision 2026/02/04
This article presents a sample code for refreshing the background color of a 2.2-inch Arduino screen, allowing users to switch between predefined colors or customize using hexadecimal or decimal codes, enhancing display control capabilities.
Introduction
The function of the program: realize the refreshing of the background color of the 2.2”screen and the switching of background color among red, white and black; there are 19 common defined color in the library, and users can also customize 4-bit hexadecimal code or decimal color code (0~65535) to alter the background color of the screen.
Sample Code
/*
* file DFRobot_ST7687S_Latch.ino
*
* @ https://github.com/DFRobot/DFRobot_ST7687S
*
* connect with your board (please reference board compatibility)
*
* controler (uno) DFRobot 2.2 inch tft lcd display
* SPI_SCK ----> SPI_SCL
* SPI_MOSI ----> SPI_MOSI
* 3 ----> cs
* 5 ----> rs
* 6 ----> wr
* 7 ----> lck
*
* show many graphics on board
*
* Copyright [DFRobot](https://www.dfrobot.com), 2016
* Copyright GNU Lesser General Public License
*
* version V1.0
* date 2017-12-7
*/
#include "DFRobot_ST7687S_Latch.h"
#ifdef __AVR__
uint8_t pin_cs = 3, pin_rs = 5, pin_wr = 6, pin_lck = 7;
#else
uint8_t pin_cs = D3, pin_rs = D5, pin_wr = D6, pin_lck = D7;
#endif
DFRobot_ST7687S_Latch tft(pin_cs, pin_rs, pin_wr, pin_lck);
void setup(void)
{
Serial.begin(115200);
tft.begin();
}
void loop(void)
{
delay(1000);
tft.fillScreen(DISPLAY_RED); //fill screen with color
delay(1000);
tft.fillScreen(DISPLAY_WHITE);
delay(1000);
tft.fillScreen(DISPLAY_BLACK);
delay(1000);
tft.fillScreen(65535);//User-defined color code 65535:white
delay(1000);
tft.fillScreen(0x0000);//User-defined color code 0x0000:black
}
Result

Was this article helpful?
