#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#define TFT_CS 12
#define TFT_DC 27
#define TFT_RST 4
#define BG_COLOR 0x5579 // light-blue
#define BORDER_COLOR 0x5BD1 // dark-gray
#define FRAME_COLOR 0xD6FC // light-gray
#define CARD_FRAME_COLOR 0x7CB4 // card frame color
#define BLUE_COLOR 0x3A7F // card blue
#define RED_COLOR 0xE887 // card red
#define GREEN_COLOR 0x16A3 // card green
#define GOLD_COLOR 0xF64A // card gold
#define NUMBER_COLOR 0xF7BE // card num
#define BLACK_COLOR 0x08A3 // card black
#define SCORE_COLOR 0x2A2B // score bg color
#define HOLDER_COLOR 0x767B // card holder color
#define CARD_WIDTH 18
#define CARD_HEIGHT 22
#define FIELD_WITDH 160
#define FIELD_HEIGHT 128
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
const uint8_t charP[] = {
0b11111000,
0b11001100,
0b11001100,
0b11111000,
0b11000000,
0b11000000,
0b11000000,
};
const uint8_t charOne[] = {
0b00110000,
0b01110000,
0b00110000,
0b00110000,
0b00110000,
0b00110000,
0b01111000,
};
const uint8_t charTwo[] = {
0b01111000,
0b11001100,
0b00001100,
0b00111000,
0b01100000,
0b11000000,
0b11111100,
};
void setup() {
Serial.begin(9600);
Serial.println(F("Hello! ST77xx TFT Test"));
tft.initR(INITR_GREENTAB);
flipScreenToILI9341();
uint16_t time = millis();
drawFieldBasis();
drawEmptyField(10, 25);
drawEmptyField(91, 25);
// drawFieldHolder(10, 25);
// drawFieldHolder(91, 25);
drawScoreChar(7, 7, charP);
drawScoreChar(15, 7, charOne);
drawScoreChar(139, 7, charP);
drawScoreChar(147, 7, charTwo);
time = millis() - time;
Serial.println(time, DEC);
delay(2000);
}
void loop() {
// put your main code here, to run repeatedly:
}
void drawScoreChar(uint16_t x, uint16_t y, const uint8_t *c) {
tft.drawBitmap(x, y, c, 6, 7, NUMBER_COLOR);
}
void flipScreenToILI9341() {
tft.setRotation(1);
uint8_t madctl = ST7735_MADCTL_BGR | ST77XX_MADCTL_MX;
tft.sendCommand(ST77XX_MADCTL, &madctl, 1);
}
void drawCard(uint16_t color, uint16_t x, uint16_t y) {
tft.fillRoundRect(x, y, CARD_WIDTH, CARD_HEIGHT, 3, FRAME_COLOR);
tft.fillRoundRect(x + 2, y + 2, 14, 15, 3, color);
tft.fillRect(x + 2, y + 19, 14, 3, color);
tft.fillRect(x + 2, y + 19, 14, 3, color);
tft.fillRect(x + 2, y + 5, 14, 9, BLACK_COLOR);
}
void drawEmptyField(uint16_t x, uint16_t y) {
for (uint8_t i = 0; i < 3; i++) {
for (uint8_t j = 0; j < 3; j++) {
drawCardHolderDirect(x + j * (CARD_WIDTH + 2) , y + i * (CARD_HEIGHT + 2));
}
}
}
void drawCardHolderDirect(uint16_t x, uint16_t y) {
tft.fillRoundRect(x, y, CARD_WIDTH, CARD_HEIGHT, 3, HOLDER_COLOR);
tft.drawFastVLine(x + 17, y + 2, 18, CARD_FRAME_COLOR);
tft.drawFastHLine(x + 2, y + 21, 14, CARD_FRAME_COLOR);
tft.drawPixel(x + 16, y + 20, CARD_FRAME_COLOR);
}
void drawFieldHolder(uint16_t initX, uint16_t initY) {
tft.startWrite();
uint16_t x, y;
for (uint8_t i = 0; i < 3; i++) {
for (uint8_t j = 0; j < 3; j++) {
x = initX + j * (CARD_WIDTH + 2);
y = initY + i * (CARD_HEIGHT + 2);
tft.writeFillRect(x, y, CARD_WIDTH, CARD_HEIGHT, HOLDER_COLOR);
tft.writeFastVLine(x + 17, y + 2, 18, CARD_FRAME_COLOR);
tft.writeFastHLine(x + 2, y + 21, 14, CARD_FRAME_COLOR);
tft.writePixel(x + 16, y + 20, CARD_FRAME_COLOR);
}
}
tft.endWrite();
}
void drawFieldBasis() {
tft.fillScreen(BG_COLOR);
tft.drawRect(79, 0, 2, FIELD_HEIGHT, BORDER_COLOR); // 1
tft.drawRect(5, 21, 69, 78, BORDER_COLOR); // 2
tft.drawRect(6, 22, 67, 76, CARD_FRAME_COLOR); // 3
tft.drawRect(86, 21, 69, 78, BORDER_COLOR); // 4
tft.drawRect(87, 22, 67, 76, CARD_FRAME_COLOR); // 5
tft.fillRect(5, 3, 18, 15, SCORE_COLOR); //6
tft.fillRect(31, 3, 18, 15, SCORE_COLOR); //7
tft.fillRect(112, 3, 18, 15, SCORE_COLOR); //8
tft.fillRect(137, 3, 18, 15, SCORE_COLOR); //9
}
void drawGameScore(uint16_t x, uint16_t y, uint8_t value) {
// assert(value < 4);
// uint16_t color = BORDER_COLOR;
tft.fillRoundRect(x + 4, y, 7, 7, 3, BORDER_COLOR);
tft.fillRoundRect(x, y + 7, 7, 7, 3, BORDER_COLOR);
tft.fillRoundRect(x + 8, y + 7, 7, 7, 3, BORDER_COLOR);
}