Class creation
This commit is contained in:
25
arduino/Screen code/Screen-code-full/displayText.cpp
Normal file
25
arduino/Screen code/Screen-code-full/displayText.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include "displayText.h"
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
//constructor
|
||||||
|
DisplayText::DisplayText(Adafruit_ST7796S_kbv& tftDisplay) : tft(tftDisplay) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisplayText::writeText(char* text, int size, int posX, int posY, int screenTime, bool center) {
|
||||||
|
if (center) {
|
||||||
|
posX = centerText(text);
|
||||||
|
}
|
||||||
|
tft.setCursor(posX, posY);
|
||||||
|
tft.setTextSize(size);
|
||||||
|
tft.println(text);
|
||||||
|
delay(screenTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DisplayText::centerText(char* text) {
|
||||||
|
int16_t x1, y1;
|
||||||
|
uint16_t w, h;
|
||||||
|
tft.getTextBounds(text, 0, 0, &x1, &y1, &w, &h);
|
||||||
|
int x = (tft.width() - w) / 2;
|
||||||
|
return x;
|
||||||
|
}
|
17
arduino/Screen code/Screen-code-full/displayText.h
Normal file
17
arduino/Screen code/Screen-code-full/displayText.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef DISPLAYTEXT_H
|
||||||
|
#define DISPLAYTEXT_H
|
||||||
|
|
||||||
|
#include "Adafruit_GFX.h"
|
||||||
|
#include "Adafruit_ST7796S_kbv.h"
|
||||||
|
|
||||||
|
class DisplayText {
|
||||||
|
private:
|
||||||
|
Adafruit_ST7796S_kbv& tft;
|
||||||
|
int centerText(char* text);
|
||||||
|
|
||||||
|
public:
|
||||||
|
DisplayText(Adafruit_ST7796S_kbv& tftDisplay);
|
||||||
|
void writeText(char* text, int size, int posX, int posY, int screenTime, bool center);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user