-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
98 lines (85 loc) · 2.34 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <Arduino.h>
#include "pin_config.h"
#include "TFT_eSPI.h" // https://github.com/Bodmer/TFT_eSPI
#define GFXFF 1
#define FONT_DELAY 1000
// https://github.com/Bodmer/TFT_eSPI/blob/master/Fonts/GFXFF/print.txt
const GFXfont* FF[] = {
&FreeMono9pt7b,
&FreeMonoBold9pt7b,
&FreeMonoOblique9pt7b,
&FreeMonoBoldOblique9pt7b,
&FreeSans9pt7b,
&FreeSansBold9pt7b,
&FreeSansOblique9pt7b,
&FreeSansBoldOblique9pt7b,
&FreeSerif9pt7b,
&FreeSerifBold9pt7b,
&FreeSerifItalic9pt7b,
&FreeSerifBoldItalic9pt7b,
};
const char* sFF[] = {
"Mono",
"Mono bold",
"Mono oblique",
"Mono bold oblique",
"Sans",
"Sans bold",
"Sans oblique",
"Sans bold oblique",
"Serif",
"Serif bold",
"Serif italic",
"Serif bold italic",
};
TFT_eSPI tft = TFT_eSPI();
void setup() {
Serial.begin(115200);
Serial.println("Hello T-Dongle-S3");
pinMode(TFT_LEDA_PIN, OUTPUT);
// Initialise TFT
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
digitalWrite(TFT_LEDA_PIN, 0);
}
void loop() {
// Draw teaser to the top left
tft.setTextDatum(TL_DATUM);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(1);
tft.setTextFont(0);
tft.drawString("All the colors", 0 ,0);
uint8_t totalFonts = sizeof(sFF) / sizeof(sFF[0]);
for (uint8_t i = 0; i < totalFonts; i++) {
// Serial debug infos
Serial.print("Font ");
Serial.print(i);
Serial.print(" of ");
Serial.print(totalFonts);
Serial.print(": ");
Serial.println(sFF[i]);
// Partially clear screen
tft.fillRect(0, 32, tft.width(), tft.height() - 32, TFT_BLACK);
// Pick a random (non-black) foreground color
tft.setTextColor(default_4bit_palette[random(1, 15)], TFT_BLACK);
// Draw sample text output in the center of the screen
tft.setFreeFont(FF[i]);
tft.setTextSize(1); // size is defined in GFX font definition
tft.setTextDatum(MC_DATUM);
tft.drawString("Hello Andi!", tft.width() / 2, tft.height() / 2, GFXFF);
// Draw font name in the bottom right
tft.setTextFont(0);
tft.setTextColor(TFT_GREENYELLOW, TFT_BLACK);
tft.setTextDatum(BR_DATUM);
tft.drawString(sFF[i], tft.width(), tft.height());
delay(FONT_DELAY);
}
// Flip da screen
if (tft.getRotation() == 1) {
tft.setRotation(3);
} else {
tft.setRotation(1);
}
tft.fillScreen(TFT_BLACK);
}