#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include <Arduino.h>
#define TFT_CS 9
#define TFT_DC 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define WIDTH 320
#define HEIGHT 240
class Window {
private:
int WindowStartX, WindowStartY; // Position of the window
int WindowWidth, WindowHeight; // Size of the window
uint16_t buffer[2500]; // Buffer with color for each pixel
public:
// Constructor to initialize the window with position and size
Window(int x, int y, int width, int height)
: WindowStartX(x), WindowStartY(y), WindowWidth(width), WindowHeight(height) {
clearBuffer();
focus();
}
// Clear the buffer
void clearBuffer() {
for (int i = 0; i < WindowWidth * WindowHeight; ++i) {
buffer[i] = 0xFFFF;
}
}
// Method to draw the window border and buffer content to the display
void focus() {
// Draw the border using the TFT functions
tft.drawRect(WindowStartX - 1, WindowStartY - 1, WindowWidth + 2, WindowHeight + 2, ILI9341_WHITE); // White border
// Draw buffer content to the display
for (int y = 0; y < WindowHeight; ++y) {
for (int x = 0; x < WindowWidth; ++x) {
tft.drawPixel(WindowStartX + x, WindowStartY + y, buffer[x + y * WindowWidth]);
}
}
}
void drawRect() {
}
};
void setup(void) {
Serial.begin(115200);
tft.begin();
tft.fillScreen(ILI9341_BLACK); // Clear screen
tft.setTextColor(ILI9341_WHITE); // Set text color
tft.setRotation(1);
Window MainWindow(10,10,50,50);
}
void loop() {
}