#include <Adafruit_GFX.h> // https://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_ILI9341.h> // https://github.com/adafruit/Adafruit_ILI9341
// #include <Adafruit_BusIO.h> //https://github.com/adafruit/Adafruit_BusIO
#define TFT_MISO 15
#define TFT_CLK 18
#define TFT_MOSI 23
#define TFT_DC 2 // incorrect DC to screen pin gives white screen
#define TFT_RST 4
#define TFT_CS 5
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(115200);
tft.begin();
// test(); // uncomment to read device results
tft.setRotation(0);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
text();
pixel();
line();
rect();
circle();
Serial.println("\nFin.");
}
void loop() {
}
void text() {
int x = 45, y = 160;
tft.setCursor(x, y);
tft.print("Hello, World!");
}
void pixel() {
int y = 180, color = ILI9341_YELLOW;
for (int x = 80; x < 180; x += 5) // increase left to right
tft.drawPixel(x, y, color);
}
void line() {
int xStart = 0, yStart = 0, xEnd = 240, yEnd = 320, color = ILI9341_RED;
tft.drawLine(xStart, yStart, xEnd, yEnd, color);
}
void rect() {
int x = 40, y = 150, width = 160, height = 40, color = ILI9341_CYAN;
tft.drawRect(x, y, width, height, color);
}
void circle() {
int x = 120, y = 170, radius = 90, color = ILI9341_GREEN;
tft.drawCircle(x, y, radius, color);
}
void test() {
uint8_t x = tft.readcommand8(ILI9341_RDMODE);
Serial.println();
Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDMADCTL);
Serial.print("MADCTL Mode : 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDPIXFMT);
Serial.print("Pixel Format : 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDIMGFMT);
Serial.print("Image Format : 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDSELFDIAG);
Serial.print("Self Diagnostic : 0x"); Serial.println(x, HEX);
while (1);
}