Added class
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "Adafruit_ST7796S_kbv.h"
|
||||
#include "headerFile.h"
|
||||
#include "displayText.h"
|
||||
int i = 0;
|
||||
|
||||
char* Question[] = {
|
||||
@@ -22,7 +23,7 @@ char* Answer[] = {
|
||||
|
||||
//simplify the name of the library
|
||||
Adafruit_ST7796S_kbv tft = Adafruit_ST7796S_kbv(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST, MISO);
|
||||
|
||||
DisplayText displayText(tft);
|
||||
|
||||
|
||||
void setup() {
|
||||
@@ -40,32 +41,29 @@ void loop() {
|
||||
tft.fillScreen(ST7796S_BLACK); // Fill the screen with black color
|
||||
// writeText(Question[0], 2, 50, 0, 0);
|
||||
// writeText(Answer[0], 2, 50, 300, 4000);
|
||||
writeText(Question[i], 3, 0, 0, 0, true);
|
||||
writeText(Answer[i], 3, 0, 200, 0, true);
|
||||
displayText.writeText(Question[i], 3, 0, 0, 0, true);
|
||||
displayText.writeText(Answer[i], 3, 0, 200, 0, true);
|
||||
delay(10000);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void writeText(char* text, int size, int posX, int posY, int screenTime, bool center){
|
||||
//if true overwrites x
|
||||
if (center){
|
||||
posX = centerText(text);
|
||||
}
|
||||
tft.setCursor(posX, posY); // Set the cursor to the top left corner
|
||||
tft.setTextSize(size); // Set textsize
|
||||
tft.println(text);
|
||||
delay(screenTime);
|
||||
}
|
||||
// void writeText(char* text, int size, int posX, int posY, int screenTime, bool center){
|
||||
// //if true overwrites x
|
||||
// if (center){
|
||||
// posX = centerText(text);
|
||||
// }
|
||||
// tft.setCursor(posX, posY); // Set the cursor to the top left corner
|
||||
// tft.setTextSize(size); // Set textsize
|
||||
// tft.println(text);
|
||||
// delay(screenTime);
|
||||
// }
|
||||
|
||||
int centerText(char* text) {
|
||||
int16_t x1, y1;
|
||||
uint16_t w, h;
|
||||
// int centerText(char* text) {
|
||||
// int16_t x1, y1;
|
||||
// uint16_t w, h;
|
||||
|
||||
tft.getTextBounds(text, 0, 0, &x1, &y1, &w, &h); // Calculate the width of the text
|
||||
int x = (tft.width() - w) / 2; // Calculate the x-coordinate for the centered text
|
||||
// tft.getTextBounds(text, 0, 0, &x1, &y1, &w, &h); // Calculate the width of the text
|
||||
// int x = (tft.width() - w) / 2; // Calculate the x-coordinate for the centered text
|
||||
|
||||
return x;
|
||||
}
|
||||
// return x;
|
||||
// }
|
Reference in New Issue
Block a user