// #include <SPI.h>
#include <Adafruit_GFX.h> // https://github.com/adafruit/Adafruit-GFX-Library
// https://learn.adafruit.com/adafruit-gfx-graphics-library/graphics-primitives
#include <Adafruit_ILI9341.h> // https://github.com/adafruit/Adafruit_ILI9341
#define TFT_RST 8
#define TFT_DC 9
#define TFT_CS 10
#define TFT_MOSI 11
#define TFT_MISO 12
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 320
#define HALF_WIDTH SCREEN_WIDTH / 2
#define HALF_HEIGHT SCREEN_HEIGHT / 2
int rowHeight = 8, colWidth = 33;
int row = 3, col = 3, chr = 0;
#define RED 0xF800 // 565 0b 11111 000000 00000 // https://rgbcolorpicker.com/565
#define ORG 0xFC00 // 565 0b 11111 100000 00000
#define YEL 0xFFE0 // 565 0b 11111 111111 00000
#define GRN 0x07E0 // 565 0b 00000 111111 00000
#define CYN 0x07FF // 565 0b 00000 111111 11111
#define BLU 0x001F // 565 0b 00000 000000 11111
#define MAG 0xF81F // 565 0b 11111 000000 11111
#define WHT 0xFFFF // 565 0b 11111 111111 11111
#define GRY 0xC618 // 565 0b 11000 110000 11000
#define BLK 0x0000 // 565 0b 00000 000000 00000
void setup() {
Serial.begin(115200);
// Serial.println();
tft.begin();
tft.setRotation(0); // 0 = none, 1 = 90CW, 2 = 180, 3 = 270CW
test();
textCharacters();
textDraw();
textSize();
graphics();
}
void loop() { }
void test() {
graphics();
int y = HALF_HEIGHT - HALF_WIDTH;
int x = HALF_WIDTH;
tft.drawPixel(x, y, WHT); // apex of large triangle
}
void textCharacters() {
tft.setCursor(col, row);
tft.setTextSize(1);
tft.setTextColor(GRN);
// tft.setTextColor(uint16_t color, uint16_t bgcolor);
// tft.setTextWrap(w); // boolea
for (int i = 0; i < 256; i++) {
if (chr < 10) tft.print(" "); // space for tens
if (chr < 100) tft.print(" "); // space for hundreds
tft.print(chr);
tft.print(" ");
tft.write(chr);
row += rowHeight;
if (row > SCREEN_HEIGHT - rowHeight) {
row = 3;
col += colWidth;
}
chr++;
tft.setCursor(col, row);
}
}
void textSize() {
tft.setCursor(0, SCREEN_HEIGHT / 3);
for (int i = 1; i < 6; i++) {
switch (i) {
case 1: tft.setTextColor(ORG); break;
case 2: tft.setTextColor(MAG); break;
case 3: tft.setTextColor(CYN); break;
case 4: tft.setTextColor(GRY); break;
case 5: tft.setTextColor(WHT); break;
}
tft.setTextSize(i);
tft.print("Size");
tft.println(i);
}
}
void textDraw() {
tft.drawChar(205, 195, 'A', BLK, GRY, 5);
tft.drawChar(205, 235, 'B', BLK, GRY, 5);
tft.drawChar(205, 275, 'C', BLK, GRY, 5);
}
void graphics() {
// tft.drawPoint(x, y, c);
tft.drawLine(0, SCREEN_HEIGHT, SCREEN_WIDTH, 0, RED);
tft.drawLine(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, ORG);
// tft.drawEllipse(x, y, rx, ry, c);
// tft.fillEllipse(x, y, rx, ry, c);
tft.drawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, YEL);
// tft.fillRect(x0, y0, x1, y1, c);
tft.drawCircle(HALF_WIDTH, HALF_HEIGHT - HALF_WIDTH, HALF_WIDTH, WHT);
tft.drawCircle(HALF_WIDTH, HALF_HEIGHT, HALF_WIDTH, BLU);
tft.drawCircle(HALF_WIDTH, HALF_HEIGHT + HALF_WIDTH, HALF_WIDTH, WHT);
// tft.fillCircle(x, y, r, c);
tft.drawRoundRect(20, 20, SCREEN_WIDTH - 40, SCREEN_HEIGHT - 40, 20, CYN); // 20 = corner radius
// tft.fillRoundRect(x, y, w, h, r, c);
tft.drawTriangle(HALF_WIDTH, HALF_HEIGHT - HALF_WIDTH, 17, 220, 223, 220, YEL);
tft.drawTriangle(HALF_WIDTH, HALF_HEIGHT + HALF_WIDTH / 2, 67, 133, 173, 133, YEL);
// tft.fillTriangle(x0, y0, x1, y1, x2, y2, color);
}