/**************************************************************************
This is a library for several Adafruit displays based on ST77* drivers.
This example works with the 1.14" DisplayTFT breakout
----> https://www.adafruit.com/product/4383
The 1.3" DisplayTFT breakout
----> https://www.adafruit.com/product/4313
The 1.47" DisplayTFT breakout
----> https://www.adafruit.com/product/5393
The 1.54" DisplayTFT breakout
----> https://www.adafruit.com/product/3787
The 1.69" DisplayTFT breakout
----> https://www.adafruit.com/product/5206
The 1.9" DisplayTFT breakout
----> https://www.adafruit.com/product/5394
The 2.0" DisplayTFT breakout
----> https://www.adafruit.com/product/4311
Check out the links above for our tutorials and wiring diagrams.
These displays use SPI to communicate, 4 or 5 pins are required to
interface (RST is optional).
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
**************************************************************************/
#include <Arduino.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#define DisplayTFT_CS1 5 //ok
#define DisplayTFT_CS2 13
#define DisplayTFT_CS3 12
#define DisplayTFT_CS4 14
#define DisplayTFT_RST 4 //ok
#define DisplayTFT_DC 2 //ok
#define DisplayTFT_SCLK 18 //ok
#define DisplayTFT_MOSI 23 //ok
// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
// to each board and not reassignable. For Arduino Uno: MOSI = pin 11 and
// SCLK = pin 13. This is the fastest mode of operation and is required if
// using the breakout board's microSD card.
Adafruit_ST7789 DisplayTFT1 = Adafruit_ST7789(DisplayTFT_CS1, DisplayTFT_DC, DisplayTFT_RST);
Adafruit_ST7789 DisplayTFT2 = Adafruit_ST7789(DisplayTFT_CS2, DisplayTFT_DC, DisplayTFT_RST);
Adafruit_ST7789 DisplayTFT3 = Adafruit_ST7789(DisplayTFT_CS3, DisplayTFT_DC, DisplayTFT_RST);
Adafruit_ST7789 DisplayTFT4 = Adafruit_ST7789(DisplayTFT_CS4, DisplayTFT_DC, DisplayTFT_RST);
// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
// tradeoff being that performance is not as fast as hardware SPI above.
//#define DisplayTFT_MOSI 11 // Data out
//#define DisplayTFT_SCLK 13 // Clock out
//Adafruit_ST7789 DisplayTFT = Adafruit_ST7789(DisplayTFT_CS, DisplayTFT_DC, DisplayTFT_MOSI, DisplayTFT_SCLK, DisplayTFT_RST);
float p = 3.1415926;
void setup(void) {
Serial.begin(9600);
Serial.print(F("Hello! ST77xx DisplayTFT Test"));
DisplayTFT1.init(240, 320); // Init ST7789 240x240
DisplayTFT1.invertDisplay(0);
DisplayTFT2.init(240, 320); // Init ST7789 240x240
DisplayTFT2.invertDisplay(0);
DisplayTFT3.init(240, 320); // Init ST7789 240x240
DisplayTFT3.invertDisplay(0);
DisplayTFT4.init(240, 320); // Init ST7789 240x240
DisplayTFT4.invertDisplay(0);
uint16_t time = millis();
DisplayTFT1.fillScreen(ST77XX_BLACK);
DisplayTFT2.fillScreen(ST77XX_BLACK);
time = millis() - time;
Serial.println(time, DEC);
delay(100);
Serial.println("TFT Init done");
DisplayTFT1.setTextSize(5);
}
void loop()
{ static bool FLAG = true;
static int CNT = 0;
CNT++;
if( CNT > 60 ) CNT = 0;
DisplayTFT1.fillScreen(ST77XX_BLACK);
DisplayTFT1.setTextColor(ST77XX_YELLOW);
DisplayTFT1.setTextWrap(true);
DisplayTFT1.setCursor(0, 0);
DisplayTFT1.print(CNT);
// DisplayTFT1.invertDisplay(FLAG);
DisplayTFT2.invertDisplay(FLAG);
DisplayTFT3.invertDisplay(FLAG);
DisplayTFT4.invertDisplay(FLAG);
delay(10);
FLAG = !FLAG;
}
void testlines(uint16_t color) {
DisplayTFT1.fillScreen(ST77XX_BLACK);
for (int16_t x=0; x < DisplayTFT1.width(); x+=6) {
DisplayTFT1.drawLine(0, 0, x, DisplayTFT1.height()-1, color);
delay(0);
}
for (int16_t y=0; y < DisplayTFT1.height(); y+=6) {
DisplayTFT1.drawLine(0, 0, DisplayTFT1.width()-1, y, color);
delay(0);
}
DisplayTFT1.fillScreen(ST77XX_BLACK);
for (int16_t x=0; x < DisplayTFT1.width(); x+=6) {
DisplayTFT1.drawLine(DisplayTFT1.width()-1, 0, x, DisplayTFT1.height()-1, color);
delay(0);
}
for (int16_t y=0; y < DisplayTFT1.height(); y+=6) {
DisplayTFT1.drawLine(DisplayTFT1.width()-1, 0, 0, y, color);
delay(0);
}
DisplayTFT1.fillScreen(ST77XX_BLACK);
for (int16_t x=0; x < DisplayTFT1.width(); x+=6) {
DisplayTFT1.drawLine(0, DisplayTFT1.height()-1, x, 0, color);
delay(0);
}
for (int16_t y=0; y < DisplayTFT1.height(); y+=6) {
DisplayTFT1.drawLine(0, DisplayTFT1.height()-1, DisplayTFT1.width()-1, y, color);
delay(0);
}
DisplayTFT1.fillScreen(ST77XX_BLACK);
for (int16_t x=0; x < DisplayTFT1.width(); x+=6) {
DisplayTFT1.drawLine(DisplayTFT1.width()-1, DisplayTFT1.height()-1, x, 0, color);
delay(0);
}
for (int16_t y=0; y < DisplayTFT1.height(); y+=6) {
DisplayTFT1.drawLine(DisplayTFT1.width()-1, DisplayTFT1.height()-1, 0, y, color);
delay(0);
}
}
void testdrawtext(char *text, uint16_t color) {
DisplayTFT1.setCursor(0, 0);
DisplayTFT1.setTextColor(color);
DisplayTFT1.setTextWrap(true);
DisplayTFT1.print(text);
}
void testfastlines(uint16_t color1, uint16_t color2) {
DisplayTFT1.fillScreen(ST77XX_BLACK);
for (int16_t y=0; y < DisplayTFT1.height(); y+=5) {
DisplayTFT1.drawFastHLine(0, y, DisplayTFT1.width(), color1);
}
for (int16_t x=0; x < DisplayTFT1.width(); x+=5) {
DisplayTFT1.drawFastVLine(x, 0, DisplayTFT1.height(), color2);
}
}
void testdrawrects(uint16_t color) {
DisplayTFT1.fillScreen(ST77XX_BLACK);
for (int16_t x=0; x < DisplayTFT1.width(); x+=6) {
DisplayTFT1.drawRect(DisplayTFT1.width()/2 -x/2, DisplayTFT1.height()/2 -x/2 , x, x, color);
}
}
void testfillrects(uint16_t color1, uint16_t color2) {
DisplayTFT1.fillScreen(ST77XX_BLACK);
for (int16_t x=DisplayTFT1.width()-1; x > 6; x-=6) {
DisplayTFT1.fillRect(DisplayTFT1.width()/2 -x/2, DisplayTFT1.height()/2 -x/2 , x, x, color1);
DisplayTFT1.drawRect(DisplayTFT1.width()/2 -x/2, DisplayTFT1.height()/2 -x/2 , x, x, color2);
}
}
void testfillcircles(uint8_t radius, uint16_t color) {
for (int16_t x=radius; x < DisplayTFT1.width(); x+=radius*2) {
for (int16_t y=radius; y < DisplayTFT1.height(); y+=radius*2) {
DisplayTFT1.fillCircle(x, y, radius, color);
}
}
}
void testdrawcircles(uint8_t radius, uint16_t color) {
for (int16_t x=0; x < DisplayTFT1.width()+radius; x+=radius*2) {
for (int16_t y=0; y < DisplayTFT1.height()+radius; y+=radius*2) {
DisplayTFT1.drawCircle(x, y, radius, color);
}
}
}
void testtriangles() {
DisplayTFT1.fillScreen(ST77XX_BLACK);
uint16_t color = 0xF800;
int t;
int w = DisplayTFT1.width()/2;
int x = DisplayTFT1.height()-1;
int y = 0;
int z = DisplayTFT1.width();
for(t = 0 ; t <= 15; t++) {
DisplayTFT1.drawTriangle(w, y, y, x, z, x, color);
x-=4;
y+=4;
z-=4;
color+=100;
}
}
void testroundrects() {
DisplayTFT1.fillScreen(ST77XX_BLACK);
uint16_t color = 100;
int i;
int t;
for(t = 0 ; t <= 4; t+=1) {
int x = 0;
int y = 0;
int w = DisplayTFT1.width()-2;
int h = DisplayTFT1.height()-2;
for(i = 0 ; i <= 16; i+=1) {
DisplayTFT1.drawRoundRect(x, y, w, h, 5, color);
x+=2;
y+=3;
w-=4;
h-=6;
color+=1100;
}
color+=100;
}
}
void DisplayTFTPrintTest() {
DisplayTFT1.setTextWrap(false);
DisplayTFT1.fillScreen(ST77XX_BLACK);
DisplayTFT1.setCursor(0, 30);
DisplayTFT1.setTextColor(ST77XX_RED);
DisplayTFT1.setTextSize(1);
DisplayTFT1.println("Hello World!");
DisplayTFT1.setTextColor(ST77XX_YELLOW);
DisplayTFT1.setTextSize(2);
DisplayTFT1.println("Hello World!");
DisplayTFT1.setTextColor(ST77XX_GREEN);
DisplayTFT1.setTextSize(3);
DisplayTFT1.println("Hello World!");
DisplayTFT1.setTextColor(ST77XX_BLUE);
DisplayTFT1.setTextSize(4);
DisplayTFT1.print(1234.567);
delay(1500);
DisplayTFT1.setCursor(0, 0);
DisplayTFT1.fillScreen(ST77XX_BLACK);
DisplayTFT1.setTextColor(ST77XX_WHITE);
DisplayTFT1.setTextSize(0);
DisplayTFT1.println("Hello World!");
DisplayTFT1.setTextSize(1);
DisplayTFT1.setTextColor(ST77XX_GREEN);
DisplayTFT1.print(p, 6);
DisplayTFT1.println(" Want pi?");
DisplayTFT1.println(" ");
DisplayTFT1.print(8675309, HEX); // print 8,675,309 out in HEX!
DisplayTFT1.println(" Print HEX!");
DisplayTFT1.println(" ");
DisplayTFT1.setTextColor(ST77XX_WHITE);
DisplayTFT1.println("Sketch has been");
DisplayTFT1.println("running for: ");
DisplayTFT1.setTextColor(ST77XX_MAGENTA);
DisplayTFT1.print(millis() / 1000);
DisplayTFT1.setTextColor(ST77XX_WHITE);
DisplayTFT1.print(" seconds.");
}
void mediabuttons() {
// play
DisplayTFT1.fillScreen(ST77XX_BLACK);
DisplayTFT1.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE);
DisplayTFT1.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED);
delay(500);
// pause
DisplayTFT1.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE);
DisplayTFT1.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN);
DisplayTFT1.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN);
delay(500);
// play color
DisplayTFT1.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE);
delay(50);
// pause color
DisplayTFT1.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED);
DisplayTFT1.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED);
// play color
DisplayTFT1.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN);
}