|
本帖最后由 suiyuan7906 于 2022-4-23 10:40 编辑
这是源码
- //抖音爆改车间主任开源代码
- //4.2寸墨水屏兼容微雪4.2寸三色墨水屏
- //文本文档命名为txt.txt存储在TF卡的根目录中,仅支持UTF-8编码,用windows文本编辑器另存为UTF-8编码
- //首次打开文档会创建索引文件,可能需要几分钟的时间,从串口监视器中可查看进度
- //2分钟无操作自动进入休眠模式,重启电源后恢复使用
- //转载保留爆改车间主任署名
- //关注“爆改车间”微信公众号获取主任更多开关代码
- //关注“爆改车间主任”抖音观看主任最新有趣视频
- #include <FS.h>
- #include <SD.h>
- //#include <time.h>
- //#include <ESP8266WiFi.h>
- //#include <ESP8266WebServer.h>
- #include <EEPROM.h>
- String txt[1];
- int page, pagemax;
- //=========================================
- //按键IO配置
- const int UP = 4;// D2;
- const int DOWN = 0;// D3;
- //=========================================
- //4.2寸墨水屏驱动配置 墨水屏驱动库GxEPD2在库管理中下载
- #include <U8g2_for_Adafruit_GFX.h>
- #include <GxEPD2_BW.h>
- //#include <GxEPD2_3C.h>
- #define GxEPD2_DISPLAY_CLASS GxEPD2_BW
- //#define GxEPD2_DISPLAY_CLASS GxEPD2_3C
- #define GxEPD2_DRIVER_CLASS GxEPD2_420 // GDEW042T2 400x300, UC8176 (IL0398)
- //#define GxEPD2_DRIVER_CLASS GxEPD2_420c
- #define MAX_DISPLAY_BUFFER_SIZE (81920ul-34000ul-5000ul) // ~34000 base use, change 5000 to your application use
- #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
- //根据驱动板自行配置墨水屏驱动IO口
- //当前使用的是黑白屏的驱动
- //三色屏使用黑白屏驱动刷新速度块,需要修改驱动文件GxEPD2_420.cpp中_InitDisplay屏幕初始化设置里writeCommand(0x30)项下面改为writeData(0x3c);
- GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(/*CS=D8*/ 15, /*DC=D2*/ 4, /*RST=D4*/ 2, /*BUSY=D1*/ 5));
- //下面一行是三色屏的驱动
- //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=D8*/ D8, /*DC=D3*/ D2, /*RST=D4*/ D4, /*BUSY=D2*/ D1)); // GDEW042Z15
- U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx;
- File SDCard;
- File file, fileSY;
- int adc;
- int runtime;
- void setup() {
- Serial.begin(115200);
- Serial.println();
- Serial.println();
- Serial.println();
- EEPROM.begin(1024);
- page = read_String(1).toInt();
- pagemax = read_String(10).toInt();
- adc = analogRead(A0);
- display.init();
- u8g2_for_adafruit_gfx.begin(display);
- Serial.print("Initializing SD card...");
- if (!SD.begin(D3)) {
- Serial.println("initialization failed!");
- return;
- }
- Serial.println("initialization done.");
- SDCard = SD.open("/");
- listDir(SDCard, 0);
- file = SD.open("txt.txt", "r");
- Serial.print("txt.txt文件大小:");
- Serial.println(file.size());
- if (!file) {
- Serial.println("没有找到txt.txt文件");
- } else {
- Serial.println("打开txt.txt文件");
- fileSY = SD.open("txtSY.txt", "r");
- if (!fileSY) {
- Serial.println("没有找到txt.txt的索引文件");
- Serial.println("开始创建txt.txt的索引文件");
- suoyin_R(File);
- } else {
- Serial.println("打开txt.txt的索引文件");
- }
- }
- gettxt_R(file, page);
- displayTXT_R();
- }
- void loop() {
- if (digitalRead(UP) == LOW) {
- delay(10);
- if (digitalRead(UP) == LOW) {
- if (page > 0)page--;
- pinMode(DOWN, OUTPUT);
- gettxt_R(file, page);
- pinMode(DOWN, INPUT);
- write_String(1, String(page));
- pinMode(UP, OUTPUT);
- displayTXT_R();
- pinMode(UP, INPUT_PULLUP);
- adc = analogRead(A0);
- adc = analogRead(A0);
- adc = analogRead(A0);
- runtime = millis();
- while (digitalRead(UP) == LOW);
- }
- }
- if (digitalRead(DOWN) == LOW) {
- delay(10);
- if (digitalRead(DOWN) == LOW) {
- page++;
- pinMode(DOWN, OUTPUT);
- gettxt_R(file, page);
- pinMode(DOWN, INPUT);
- write_String(1, String(page));
- pinMode(UP, OUTPUT);
- displayTXT_R();
- pinMode(UP, INPUT_PULLUP);
- adc = analogRead(A0);
- adc = analogRead(A0);
- adc = analogRead(A0);
- runtime = millis();
- while (digitalRead(DOWN) == LOW);
- }
- }
- if ((millis() - runtime) > 120000) {
- Serial.println("进入休眠状态");
- pinMode(UP, OUTPUT);
- u8g2_for_adafruit_gfx.setFont(u8g2_font_wqy14_t_gb2312);
- u8g2_for_adafruit_gfx.setFontMode(1);
- u8g2_for_adafruit_gfx.setFontDirection(0);
- u8g2_for_adafruit_gfx.setBackgroundColor(GxEPD_BLACK);
- u8g2_for_adafruit_gfx.setForegroundColor(GxEPD_WHITE);
- display.setPartialWindow(110, 0, 95, 14);
- display.firstPage();
- do
- {
- display.fillScreen(GxEPD_BLACK);
- u8g2_for_adafruit_gfx.setCursor(115, 14);
- u8g2_for_adafruit_gfx.print("进入休眠状态");
- }
- while (display.nextPage());
- ESP.deepSleep(0);
- }
- }
- void displayTXT_R() {
- u8g2_for_adafruit_gfx.setFont(u8g2_font_wqy14_t_gb2312);
- u8g2_for_adafruit_gfx.setFontMode(1); // use u8g2 transparent mode (this is default)
- u8g2_for_adafruit_gfx.setFontDirection(0); // left to right (this is default)
- u8g2_for_adafruit_gfx.setForegroundColor(GxEPD_BLACK); // apply Adafruit GFX color
- u8g2_for_adafruit_gfx.setBackgroundColor(GxEPD_WHITE);
- display.setRotation(1);
- display.setFullWindow();
- display.firstPage();
- do
- {
- display.fillScreen(GxEPD_WHITE);
- u8g2_for_adafruit_gfx.setCursor(0, 14);
- String H = "电池电压:" + String(float(adc) * 405 / 100000) + "V";
- u8g2_for_adafruit_gfx.print(H);
- H = "页:" + String(page + 1) + "/" + String(pagemax);
- u8g2_for_adafruit_gfx.setCursor(300 - (H.length() * 6), 14);
- u8g2_for_adafruit_gfx.print(H);
- for (int j = 0; j < 24; j++) {
- u8g2_for_adafruit_gfx.setCursor(0, 16 * (j + 2));
- u8g2_for_adafruit_gfx.print(txt[j]);
- }
- }
- while (display.nextPage());
- Serial.println("显示结束");
- display.hibernate();
- }
- void listDir(File dir, int numTabs) {
- while (true) {
- File entry = dir.openNextFile();
- if (! entry) {
- // no more files
- break;
- }
- for (uint8_t i = 0; i < numTabs; i++) {
- Serial.print('\t');
- }
- Serial.print(entry.name());
- if (entry.isDirectory()) {
- Serial.println("/");
- listDir(entry, numTabs + 1);
- } else {
- // files have sizes, directories do not
- Serial.print("\t\t");
- Serial.print(entry.size(), DEC);
- time_t cr = entry.getCreationTime();
- time_t lw = entry.getLastWrite();
- struct tm * tmstruct = localtime(&cr);
- Serial.printf("\tCREATION: %d-%02d-%02d %02d:%02d:%02d", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
- tmstruct = localtime(&lw);
- Serial.printf("\tLAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
- }
- entry.close();
- }
- }
- //TXT读取函数_竖版
- void gettxt_R(File file, int Y) {
- int i = 0, l = 0, d = 0;
- int address = 0;
- if (Y != 0) {
- File SYfile = SD.open("txtSY.txt", "r");
- String ST_L;
- while (SYfile.available()) {
- byte ST_T = SYfile.read();
- ST_L += (char)ST_T;
- if (ST_T == '\n') {
- if (ST_L.substring(ST_L.indexOf("L") + 1, ST_L.indexOf(":")).toInt() == Y) {
- address = ST_L.substring(ST_L.indexOf(":") + 1, ST_L.indexOf("\n")).toInt();
- //Serial.println(address);
- break;
- } else {
- ST_L = "";
- }
- }
- }
- }
- file.seek(address, SeekSet);
- txt[0] = "";
- while (file.available()) {
- byte t = file.read();
- if ((t <= 0xF7) && (t >= 0xB0)) { //中文字符 UTF-8一个中文字符占3个字节
- txt[l] += (char)t;
- txt[l] += (char)file.read();
- txt[l] += (char)file.read();
- i = i + 3;
- d = d + 3;
- } else if (t == 0xE3) {
- txt[l] += (char)t;
- txt[l] += (char)file.read();
- txt[l] += (char)file.read();
- i = i + 3;
- d = d + 3;
- }
- else if (t == '\n') { //遇到换行符直接换行
- //txt[l] += (char)t;
- i++;
- l++;
- d = 0;
- txt[l] = "";
- }
- else { //英文字符 一个字符占用1个字节
- txt[l] += (char)t;
- i++;
- d++;
- }
- if (d > 60) { //一行满60个字节换行
- d = 0;
- l++;
- txt[l] = "";
- }
- if (l >= 24) { //一页显示24行 停止获取
- break;
- }
- }
- }
- //索引文件生成函数竖版
- void suoyin_R(File file) {
- unsigned long i = 0, l = 0, d = 0, y = 0;
- int s = file.size();
- String adds;
- int v;
- SD.remove("txtSY.txt");
- File SYfile = SD.open("txtSY.txt", "a");
- while (file.available()) {
- byte t = file.read();
- if ((t <= 0xF7) && (t >= 0xB0)) { //中文字符 UTF-8一个中文字符占3个字节
- t = file.read();
- t = file.read();
- i = i + 3;
- d = d + 3;
- } else if (t == 0xE3) {
- txt[l] += (char)t;
- txt[l] += (char)file.read();
- txt[l] += (char)file.read();
- i = i + 3;
- d = d + 3;
- }
- else if (t == '\n') { //遇到换行符直接换行
- //txt[l] += (char)t;
- i++;
- l++;
- d = 0;
- }
- else { //英文字符 一个字符占用1个字节
- txt[l] += (char)t;
- i++;
- d++;
- }
- if (d > 60) { //一行满60个字节换行
- d = 0;
- l++;
- }
- if (l >= 24) { //一页显示24行 停止获取
- long t = file.position();
- // Serial.print("L");
- // Serial.print(y+1);
- // Serial.print(":");
- // Serial.println(String(t));
- float value = (float(t) / float(s)) * 100;
- if (v != int(value)) {
- v = int(value);
- Serial.print("处理进度:");
- Serial.print(v);
- Serial.println(" %");
- }
- // Serial.print(adds);
- SYfile.print("L");
- SYfile.print(String(y + 1));
- SYfile.print(":");
- SYfile.print(String(t));
- SYfile.print("\n");
- l = 0;
- y++;
- }
- if (i >= s) {
- write_String(10, String(y + 1));
- break;
- }
- }
- Serial.print(adds);
- SYfile.close();
- write_String(1, "0");
- delay(1000);
- Serial.println("重启");
- ESP.restart();
- }
- void write_String(int a, String str) {
- EEPROM.write(a, str.length());
- for (int i = 0; i < str.length(); i++) {
- EEPROM.write(a + 1 + i, str[i]);
- }
- EEPROM.commit();
- }
- String read_String(int a) {
- String data = "";
- for (int i = 0; i < EEPROM.read(a); i++) {
- data += char(EEPROM.read(a + 1 + i));
- }
- return data;
- }
复制代码
这是错误截图
这是截图
正在编译项目...
"C:\\Users\\suiyu\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\python3\\3.7.2-post1/python3" "C:\\Users\\suiyu\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.0.1/tools/signing.py" --mode header --publickey "E:\\电子书\\EPD_BOOK_v0.4_TF/public.key" --out "C:\\Users\\suiyu\\AppData\\Local\\Temp\\arduino_build_892159/core/Updater_Signing.h"
"C:\\Users\\suiyu\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\xtensa-lx106-elf-gcc\\3.0.3-gcc10.3-9bcba0b/bin/xtensa-lx106-elf-g++" -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -D_GNU_SOURCE "-IC:\\Users\\suiyu\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.0.1/tools/sdk/include" "-IC:\\Users\\suiyu\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.0.1/tools/sdk/lwip2/include" "-IC:\\Users\\suiyu\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.0.1/tools/sdk/libc/xtensa-lx106-elf/include" "-IC:\\Users\\suiyu\\AppData\\Local\\Temp\\arduino_build_892159/core" -c -w -Werror=return-type -Os -g -free -fipa-pta -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=gnu++17 -MMD -ffunction-sections -fdata-sections -fno-exceptions -DMMU_IRAM_SIZE=0x8000 -DMMU_ICACHE_SIZE=0x8000 -DNONOSDK22x_190703=1 -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DLWIP_FEATURES=1 -DLWIP_IPV6=0 -DARDUINO=10818 -DARDUINO_ESP8266_NODEMCU_ESP12E -DARDUINO_ARCH_ESP8266 "-DARDUINO_BOARD=\"ESP8266_NODEMCU_ESP12E\"" -DLED_BUILTIN=2 -DFLASHMODE_DIO -DESP8266 "-IC:\\Users\\suiyu\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.0.1\\cores\\esp8266" "-IC:\\Users\\suiyu\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.0.1\\variants\\nodemcu" "-IC:\\Users\\suiyu\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.0.1\\libraries\\SD\\src" "-IC:\\Users\\suiyu\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.0.1\\libraries\\SDFS\\src" "-IC:\\Users\\suiyu\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.0.1\\libraries\\SPI" "-IC:\\Users\\suiyu\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.0.1\\libraries\\ESP8266SdFat\\src" "-IC:\\Users\\suiyu\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.0.1\\libraries\\EEPROM" "-ID:\\Program Files (x86)\\Arduino\\libraries\\U8g2_for_Adafruit_GFX\\src" "-ID:\\Program Files (x86)\\Arduino\\libraries\\Adafruit_GFX_Library" "-ID:\\Program Files (x86)\\Arduino\\libraries\\GxEPD2\\src" "-ID:\\Program Files (x86)\\Arduino\\libraries\\Adafruit_BusIO" "-IC:\\Users\\suiyu\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.0.1\\libraries\\Wire" "C:\\Users\\suiyu\\AppData\\Local\\Temp\\arduino_build_892159\\sketch\\EPD_BOOK_v0.4_TF.ino.cpp" -o "C:\\Users\\suiyu\\AppData\\Local\\Temp\\arduino_build_892159\\sketch\\EPD_BOOK_v0.4_TF.ino.cpp.o"
E:\电子书\EPD_BOOK_v0.4_TF\EPD_BOOK_v0.4_TF.ino: In function 'void setup()':
EPD_BOOK_v0.4_TF:88:20: error: expected primary-expression before ')' token
使用 2.0.0 版本的库 SD 在文件夹: C:\Users\suiyu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\SD
使用 0.1.0 版本的库 SDFS 在文件夹: C:\Users\suiyu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\SDFS
使用 1.0 版本的库 SPI 在文件夹: C:\Users\suiyu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\SPI
使用 2.0.2 版本的库 ESP8266SdFat 在文件夹: C:\Users\suiyu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\ESP8266SdFat
使用 1.0 版本的库 EEPROM 在文件夹: C:\Users\suiyu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\EEPROM
使用 1.8.0 版本的库 U8g2_for_Adafruit_GFX 在文件夹: D:\Program Files (x86)\Arduino\libraries\U8g2_for_Adafruit_GFX
使用 1.10.14 版本的库 Adafruit_GFX_Library 在文件夹: D:\Program Files (x86)\Arduino\libraries\Adafruit_GFX_Library
使用 1.3.1 版本的库 GxEPD2 在文件夹: D:\Program Files (x86)\Arduino\libraries\GxEPD2
使用 1.11.3 版本的库 Adafruit_BusIO 在文件夹: D:\Program Files (x86)\Arduino\libraries\Adafruit_BusIO
使用 1.0 版本的库 Wire 在文件夹: C:\Users\suiyu\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.1\libraries\Wire
exit status 1
expected primary-expression before ')' token
求大佬们指点,这是哪里的问题,是库的问题还是代码的问题啊。感谢
|
|