#include "SPI.h"
#include "GC9A01A_t3n.h"
// *************** Change to your Pin numbers ***************
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
#define TFT_SCK 13
//#define TFT_MISO 12
#define TFT_MOSI 11
GC9A01A_t3n tft_9A01A = GC9A01A_t3n(TFT_CS, TFT_DC, TFT_RST);
#include <ST7735_t3.h> // Hardware-specific library
#include <ST7789_t3.h> // Hardware-specific library
ST7789_t3 tft_7789 = ST7789_t3(3, 4, 26, 27, 5);
#include <ST7735_t3.h> // Hardware-specific library
#include <ST7789_t3.h> // Hardware-specific library
float p = 3.1415926;
void setup() {
while (!Serial && millis() < 5000) ; // wait for Arduino Serial Monitor
Serial.begin(9600);
delay(500);
tft_9A01A.begin();
tft_7789.init(240, 320); // Init ST7789 320x240
tft_7789.fillScreen(ST7735_BLACK);
// large block of text
tft_7789.fillScreen(ST7735_BLACK);
testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST7735_WHITE);
delay(1000);
// tft print function!
tftPrintTest();
delay(4000);
// a single pixel
tft_7789.drawPixel(tft_7789.width()/2, tft_7789.height()/2, ST7735_GREEN);
delay(500);
// line draw test
testlines(ST7735_YELLOW);
delay(1000);
// optimized lines
testfastlines(ST7735_RED, ST7735_BLUE);
delay(1000);
testdrawrects(ST7735_GREEN);
delay(1000);
testfillrects(ST7735_YELLOW, ST7735_MAGENTA);
delay(1000);
tft_7789.fillScreen(ST7735_BLACK);
testfillcircles(10, ST7735_BLUE);
testdrawcircles(10, ST7735_WHITE);
delay(500);
testroundrects();
delay(1000);
testtriangles();
delay(1000);
mediabuttons();
delay(500);
Serial.println("done");
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
}
void testlines(uint16_t color) {
tft_7789.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft_7789.width(); x+=6) {
tft_7789.drawLine(0, 0, x, tft_7789.height()-1, color);
delay(200);
}
for (int16_t y=0; y < tft_7789.height(); y+=6) {
tft_7789.drawLine(0, 0, tft_7789.width()-1, y, color);
}
tft_7789.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft_7789.width(); x+=6) {
tft_7789.drawLine(tft_7789.width()-1, 0, x, tft_7789.height()-1, color);
}
for (int16_t y=0; y < tft_7789.height(); y+=6) {
tft_7789.drawLine(tft_7789.width()-1, 0, 0, y, color);
}
tft_7789.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft_7789.width(); x+=6) {
tft_7789.drawLine(0, tft_7789.height()-1, x, 0, color);
}
for (int16_t y=0; y < tft_7789.height(); y+=6) {
tft_7789.drawLine(0, tft_7789.height()-1, tft_7789.width()-1, y, color);
}
tft_7789.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft_7789.width(); x+=6) {
tft_7789.drawLine(tft_7789.width()-1, tft_7789.height()-1, x, 0, color);
}
for (int16_t y=0; y < tft_7789.height(); y+=6) {
tft_7789.drawLine(tft_7789.width()-1, tft_7789.height()-1, 0, y, color);
}
}
void testdrawtext(const char *text, uint16_t color) {
tft_7789.setCursor(0, 0);
tft_7789.setTextColor(color);
tft_7789.setTextWrap(true);
tft_7789.print(text);
}
void testfastlines(uint16_t color1, uint16_t color2) {
tft_7789.fillScreen(ST7735_BLACK);
for (int16_t y=0; y < tft_7789.height(); y+=5) {
tft_7789.drawFastHLine(0, y, tft_7789.width(), color1);
}
for (int16_t x=0; x < tft_7789.width(); x+=5) {
tft_7789.drawFastVLine(x, 0, tft_7789.height(), color2);
}
}
void testdrawrects(uint16_t color) {
tft_7789.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft_7789.width(); x+=6) {
tft_7789.drawRect(tft_7789.width()/2 -x/2, tft_7789.height()/2 -x/2 , x, x, color);
}
}
void testfillrects(uint16_t color1, uint16_t color2) {
tft_7789.fillScreen(ST7735_BLACK);
for (int16_t x=tft_7789.width()-1; x > 6; x-=6) {
tft_7789.fillRect(tft_7789.width()/2 -x/2, tft_7789.height()/2 -x/2 , x, x, color1);
tft_7789.drawRect(tft_7789.width()/2 -x/2, tft_7789.height()/2 -x/2 , x, x, color2);
}
}
void testfillcircles(uint8_t radius, uint16_t color) {
for (int16_t x=radius; x < tft_7789.width(); x+=radius*2) {
for (int16_t y=radius; y < tft_7789.height(); y+=radius*2) {
tft_7789.fillCircle(x, y, radius, color);
}
}
}
void testdrawcircles(uint8_t radius, uint16_t color) {
for (int16_t x=0; x < tft_7789.width()+radius; x+=radius*2) {
for (int16_t y=0; y < tft_7789.height()+radius; y+=radius*2) {
tft_7789.drawCircle(x, y, radius, color);
}
}
}
void testtriangles() {
tft_7789.fillScreen(ST7735_BLACK);
int color = 0xF800;
int t;
int w = tft_7789.width()/2;
int x = tft_7789.height()-1;
int y = 0;
int z = tft_7789.width();
for(t = 0 ; t <= 15; t+=1) {
tft_7789.drawTriangle(w, y, y, x, z, x, color);
x-=4;
y+=4;
z-=4;
color+=100;
}
}
void testroundrects() {
tft_7789.fillScreen(ST7735_BLACK);
int color = 100;
int i;
int t;
for(t = 0 ; t <= 4; t+=1) {
int x = 0;
int y = 0;
int w = tft_7789.width()-2;
int h = tft_7789.height()-2;
for(i = 0 ; i <= 16; i+=1) {
tft_7789.drawRoundRect(x, y, w, h, 5, color);
x+=2;
y+=3;
w-=4;
h-=6;
color+=1100;
}
color+=100;
}
}
void tftPrintTest() {
tft_7789.setTextWrap(false);
tft_7789.fillScreen(ST7735_BLACK);
tft_7789.setCursor(0, 30);
tft_7789.setTextColor(ST7735_RED);
tft_7789.setTextSize(1);
tft_7789.println("Hello World!");
tft_7789.setTextColor(ST7735_YELLOW);
tft_7789.setTextSize(2);
tft_7789.println("Hello World!");
tft_7789.setTextColor(ST7735_GREEN);
tft_7789.setTextSize(3);
tft_7789.println("Hello World!");
tft_7789.setTextColor(ST7735_BLUE);
tft_7789.setTextSize(4);
tft_7789.print(1234.567);
delay(1500);
tft_7789.setCursor(0, 0);
tft_7789.fillScreen(ST7735_BLACK);
tft_7789.setTextColor(ST7735_WHITE);
tft_7789.setTextSize(0);
tft_7789.println("Hello World!");
tft_7789.setTextSize(1);
tft_7789.setTextColor(ST7735_GREEN);
tft_7789.print(p, 6);
tft_7789.println(" Want pi?");
tft_7789.println(" ");
tft_7789.print(8675309, HEX); // print 8,675,309 out in HEX!
tft_7789.println(" Print HEX!");
tft_7789.println(" ");
tft_7789.setTextColor(ST7735_WHITE);
tft_7789.println("Sketch has been");
tft_7789.println("running for: ");
tft_7789.setTextColor(ST7735_MAGENTA);
tft_7789.print(millis() / 1000);
tft_7789.setTextColor(ST7735_WHITE);
tft_7789.print(" seconds.");
}
void mediabuttons() {
// play
tft_7789.fillScreen(ST7735_BLACK);
tft_7789.fillRoundRect(25, 10, 78, 60, 8, ST7735_WHITE);
tft_7789.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_RED);
delay(500);
// pause
tft_7789.fillRoundRect(25, 90, 78, 60, 8, ST7735_WHITE);
tft_7789.fillRoundRect(39, 98, 20, 45, 5, ST7735_GREEN);
tft_7789.fillRoundRect(69, 98, 20, 45, 5, ST7735_GREEN);
delay(500);
// play color
tft_7789.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_BLUE);
delay(50);
// pause color
tft_7789.fillRoundRect(39, 98, 20, 45, 5, ST7735_RED);
tft_7789.fillRoundRect(69, 98, 20, 45, 5, ST7735_RED);
// play color
tft_7789.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_GREEN);
}