Переделанный скетч из библиотеки.
Заливка цвета с названием цвета.
За delay, заранее извиняюсь.
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000 /* 0, 0, 0 */
#define NAVY 0x000F /* 0, 0, 128 */
#define DARKGREEN 0x03E0 /* 0, 128, 0 */
#define DARKCYAN 0x03EF /* 0, 128, 128 */
#define MAROON 0x7800 /* 128, 0, 0 */
#define PURPLE 0x780F /* 128, 0, 128 */
#define OLIVE 0x7BE0 /* 128, 128, 0 */
#define LIGHTGREY 0xC618 /* 192, 192, 192 */
#define DARKGREY 0x7BEF /* 128, 128, 128 */
#define BLUE 0x001F /* 0, 0, 255 */
#define GREEN 0x07E0 /* 0, 255, 0 */
#define CYAN 0x07FF /* 0, 255, 255 */
#define RED 0xF800 /* 255, 0, 0 */
#define MAGENTA 0xF81F /* 255, 0, 255 */
#define YELLOW 0xFFE0 /* 255, 255, 0 */
#define WHITE 0xFFFF /* 255, 255, 255 */
#define ORANGE 0xFDA0 /* 255, 180, 0 */
#define GREENYELLOW 0xB7E0 /* 180, 255, 0 */
#define PINK 0xFC9F
uint16_t version = MCUFRIEND_KBV_H_;
void setup()
{
Serial.begin(9600);
if (!Serial) delay(5000); //allow some time for Leonardo
uint16_t ID = tft.readID(); //
Serial.println(F("Diagnose whether this controller is supported"));
Serial.println(F("There are FAQs in extras/mcufriend_how_to.txt"));
Serial.println(F(""));
Serial.print(F("tft.readID() finds: ID = 0x"));
Serial.println(ID, HEX);
Serial.println(F(""));
Serial.print(F("MCUFRIEND_kbv version: "));
Serial.print(version/100);
Serial.print(F("."));
Serial.print((version / 10) % 10);
Serial.print(F("."));
Serial.println(version % 10);
Serial.println(F(""));
if (ID == 0x0404) {
Serial.println(F("Probably a write-only Mega2560 Shield"));
Serial.println(F("#define USE_SPECIAL in mcufriend_shield.h"));
Serial.println(F("#define appropriate SPECIAL in mcufriend_special.h"));
Serial.println(F("e.g. USE_MEGA_16BIT_SHIELD"));
Serial.println(F("e.g. USE_MEGA_8BIT_SHIELD"));
Serial.println(F("Hint. A Mega2560 Shield has a 18x2 male header"));
Serial.println(F("Often a row of resistor-packs near the 18x2"));
Serial.println(F("RP1-RP7 implies 16-bit but it might be 8-bit"));
Serial.println(F("RP1-RP4 or RP1-RP5 can only be 8-bit"));
}
if (ID == 0xD3D3) {
uint16_t guess_ID = 0x9481; // write-only shield
Serial.println(F("Probably a write-only Mega2560 Shield"));
Serial.print(F("Try to force ID = 0x"));
Serial.println(guess_ID, HEX);
tft.begin(guess_ID);
}
else tft.begin(ID);
Serial.println(F(""));
if (tft.width() == 0) {
Serial.println(F("This ID is not supported"));
Serial.println(F("look up ID in extras/mcufriend_how_to.txt"));
Serial.println(F("you may need to edit MCUFRIEND_kbv.cpp"));
Serial.println(F("to enable support for this ID"));
Serial.println(F("e.g. #define SUPPORT_8347D"));
Serial.println(F(""));
Serial.println(F("New controllers appear on Ebay often"));
Serial.println(F("If your ID is not supported"));
Serial.println(F("run LCD_ID_readreg.ino from examples/"));
Serial.println(F("Copy-Paste the output from the Serial Terminal"));
Serial.println(F("to a message in Displays topic on Arduino Forum"));
Serial.println(F("or to Issues on GitHub"));
Serial.println(F(""));
Serial.println(F("Note that OPEN-SMART boards have diff pinout"));
Serial.println(F("Edit the pin defines in LCD_ID_readreg to match"));
Serial.println(F("Edit mcufiend_shield.h for USE_SPECIAL"));
Serial.println(F("Edit mcufiend_special.h for USE_OPENSMART_SHIELD_PINOUT"));
while (1); //just die
} else {
Serial.print(F("PORTRAIT is "));
Serial.print(tft.width());
Serial.print(F(" x "));
Serial.println(tft.height());
Serial.println(F(""));
Serial.println(F("Run the examples/graphictest_kbv sketch"));
Serial.println(F("All colours, text, directions, rotations, scrolls"));
Serial.println(F("should work. If there is a problem, make notes on paper"));
Serial.println(F("Post accurate description of problem to Forum"));
Serial.println(F("Or post a link to a video (or photos)"));
Serial.println(F(""));
Serial.println(F("I rely on good information from remote users"));
}
}
void loop()
{
tft.setCursor(50, 50);
tft.fillScreen(RED); /* 255, 0, 255 */
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("RED");
delay(1000);
tft.fillScreen(GREEN); /* 0, 255, 0 */
tft.setCursor(50, 100);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("GREEN");
delay(1000);
tft.fillScreen(BLUE); /* 0, 0, 255 */
tft.setCursor(50, 50);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("BLUE");
delay(1000);
tft.fillScreen(WHITE); /* 255, 255, 255 */
tft.setCursor(50, 100);
tft.setTextColor(BLACK); tft.setTextSize(3);
tft.println("WHITE");
delay(1000);
tft.fillScreen(BLACK); /* 0, 0, 0 */
tft.setCursor(50, 50);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("BLACK");
delay(1000);
tft.fillScreen(NAVY); /* 0, 0, 128 */
tft.setCursor(50, 100);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("NAVY");
delay(1000);
tft.fillScreen(DARKCYAN); /* 0, 128, 128 */
tft.setCursor(50, 50);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("DARKCYAN");
delay(1000);
tft.fillScreen(MAROON); /* 128, 0, 0 */
tft.setCursor(50, 100);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("MAROON");
delay(1000);
tft.fillScreen(PURPLE); /* 128, 0, 128 */
tft.setCursor(50, 50);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("PURPLE");
delay(1000);
tft.fillScreen(OLIVE); /* 128, 128, 0 */
tft.setCursor(50, 100);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("OLIVE");
delay(1000);
tft.fillScreen(LIGHTGREY); /* 192, 192, 192 */
tft.setCursor(50, 50);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("LIGHTGREY");
delay(1000);
tft.fillScreen(DARKGREY); /* 128, 128, 128 */
tft.setCursor(50, 100);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("DARKGREY");
delay(1000);
tft.fillScreen(CYAN); /* 0, 255, 255 */
tft.setCursor(50, 50);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("CYAN");
delay(1000);
tft.fillScreen(YELLOW); /* 255, 255, 0 */
tft.setCursor(50, 100);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("YELLOW");
delay(1000);
tft.fillScreen(ORANGE); /* 255, 180, 0 */
tft.setCursor(50, 50);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("ORANGE");
delay(1000);
tft.fillScreen(GREENYELLOW); /* 180, 255, 0 */
tft.setCursor(50, 100);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("GREENYELLOW");
delay(1000);
tft.fillScreen(PINK);
tft.setCursor(50, 50);
tft.setTextColor(WHITE); tft.setTextSize(3);
tft.println("PINK");
delay(2000);
}