first commit

This commit is contained in:
2025-01-10 15:20:33 +08:00
commit 4f5d2aa650
66 changed files with 15921 additions and 0 deletions

82
TFT-ESP32/test/test.cpp Normal file
View File

@ -0,0 +1,82 @@
#include <TFT_eSPI.h> // TFT 显示屏库
TFT_eSPI tft = TFT_eSPI(); // 初始化 TFT 实例
const int screenWidth = 240; // 根据你的屏幕分辨率设置
const int screenHeight = 320;
const int byteWidth = (screenWidth + 7) / 8; // 每行需要的字节数
// 数组用于存储二值化后的屏幕数据
uint8_t binaryImage[screenHeight][byteWidth];
// 将屏幕数据读取并二值化,存储到数组中
void binaryScreenToArray()
{
for (int y = 0; y < screenHeight; y++)
{
uint8_t byteValue = 0;
for (int x = 0; x < screenWidth; x++)
{
// 读取像素颜色
uint16_t color = tft.readPixel(x, y);
// 将颜色二值化假设TFT_WHITE为白色其它为黑色
if (color == TFT_WHITE)
{
byteValue |= (1 << (7 - (x % 8))); // 设置当前位为1白色
}
// 每8个像素存储为一个字节
if (x % 8 == 7 || x == screenWidth - 1)
{
binaryImage[y][x / 8] = byteValue;
byteValue = 0;
}
}
}
}
// 将二值化后的屏幕数据通过串口发送到电脑,值之间用逗号隔开
void sendArrayToPC()
{
Serial.println("Start sending binary screen data:");
for (int y = 0; y < screenHeight; y++)
{
for (int x = 0; x < byteWidth; x++)
{
Serial.print(binaryImage[y][x], HEX); // 以十六进制格式发送每个字节
// 如果不是最后一个字节,则添加逗号
if (x < byteWidth - 1)
{
Serial.print(","); // 用逗号分隔
}
}
Serial.println(); // 每行结束后换行
}
Serial.println("Binary screen data sent.");
}
void setup()
{
Serial.begin(115200); // 初始化串口通信
tft.init(); // 初始化屏幕
tft.setRotation(1); // 根据需要设置屏幕的旋转
tft.fillScreen(TFT_BLACK); // 将屏幕设置为黑色
// 绘制一些内容(测试用)
tft.fillCircle(120, 160, 50, TFT_WHITE); // 在屏幕中间绘制一个白色的圆圈
// 读取并二值化屏幕内容
binaryScreenToArray();
// 将二值化后的数组通过串口传输到电脑
sendArrayToPC();
}
void loop()
{
// 主要功能在 setup 中执行loop 中不做任何操作
}