以下是主要代码 
 
- #include <Arduino.h> 
 - #include "TFT_eSPI.h" 
 - #include "MINGO.h" 
 - #include "Flower_240x280.h" 
 - 
 - #define BL 4 
 - #define inLed 2 
 - 
 - #define v_R 34 
 - 
 - #define b_1 35 
 - #define b_2 33 
 - #define b_3 25 
 - #define b_4 32 
 - 
 - // TFT 设置
 - TFT_eSPI tft = TFT_eSPI(); // 调用自定义库
 - TFT_eSprite spritte = TFT_eSprite(&tft); // 创建 Sprite 对象“spritte” 
 - 
 - 
 - // 菜单设置
 - int screenW = 240; 
 - int screenH= 280; 
 - int textWidth; 
 - int x; 
 - 
 - bool mainMenu = true ; 
 - bool subMenu = false; 
 - bool wait = false; 
 - //SubMenu 
 - const int menuCount = 4; 
 - bool menuChange = true; 
 - int selectedOption = 0; 
 - 
 - const char* menuText[menuCount] = {"亮度","时间","设置","关于"}; 
 - // 时间设置菜单
 - 
 - // 页面处理程序
 - int page IRAM_ATTR = 0; 
 - bool pageChange = true; // 在上一页完成加载之前,停止更改页面的代码
 - bool pageRefresh = true; // 清理页面
 - 
 - //时间
 - volatile int sec IRAM_ATTR= 50; 
 - volatile int minutes IRAM_ATTR= 59; 
 - volatile int hrs IRAM_ATTR= 23; 
 - volatile int days IRAM_ATTR= 7; 
 - volatile int months IRAM_ATTR= 4; 
 - volatile int yrs IRAM_ATTR= 2024; 
 - 
 - volatile int days_Max IRAM_ATTR; 
 - volatile int daysOfWeekCount IRAM_ATTR; 
 - 
 - const char* daysOfWeek[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 
 - const char* monthsOfYear[] = {"NULL","January", "February", "March", "April", "May", "June", "July", "August", "September", "Octobor", "November", "December"}; 
 - 
 - const unsigned long interval = 1000; 
 - // 
 - // 输入
 - int 电压;
 - bool inp1,inp2,inp3,inp4; 
 - 
 - 
 - // 亮度控制
 - int mapRange(int input, int input_start, int input_end, int output_start,int output_end) { 
 -     return (input - input_start) * (output_end - output_start) / (input_end - input_start) + output_start; 
 - } 
 - int brighten = 80; 
 - int Level = 4; 
 - 
 - //时间菜单控制
 - int timeMenu_Select = 0; 
 - const int timeMenu = 3; 
 - bool timePage = false; 
 - 
 - int clockSelect = 0; 
 -     int dateSelect = 0; 
 - ////////////////////////////////////////////////////////////////////////////////////////////// 
 - void input(void *pvParameters); 
 - void v_Read(void *pvParameters); 
 - void tft_page(void *pvParameters); 
 - void onTimer(TimerHandle_t xTimer); 
 - 
 - 
 - void setup()
 - { 
 - 
 -     Serial.begin(115200);
 - 
 -   pinMode(b_1,输入);pinMode(b_2,输入);pinMode(b_3,输入);pinMode(b_4,输入);pinMode(v_R,输入); //设置模式
 -   pinMode(BL,输出);pinMode(inLed,输出); 
 -  
 -   
 -   
 -   //设置TFT 
 -     tft.init(); 
 -     tft.setRotation(0); 
 -     tft.setSwapBytes(true); 
 -     tft.fillScreen(TFT_ORANGE); 
 - 
 -       analogWrite(BL, 0); 
 -         // for (int i = 0; i < 3; i++) { 
 -         // digitalWrite(inLed, HIGH); // 打开LED 
 -         // delay(500); // 等待500毫秒(0.5秒)
 -         // digitalWrite(inLed, LOW); // 关闭LED 
 -         // delay(500); // 再等待 500 毫秒
 -         // } 
 -       digitalWrite(inLed, HIGH); 
 -       analogWrite(BL, brighten); 
 - 
 -   xTaskCreatePinnedToCore(input,"button", 1024, NULL, 1, NULL, 1); // 核心 1 
 -   xTaskCreatePinnedToCore(v_Read,"Voltage Read",1024, NULL, 5, NULL, 0); 
 -   xTaskCreatePinnedToCore(tft_page,"Page of TFT",20000, NULL, 2, NULL, 1); 
 - 
 -   TimerHandle_t timerHandle = xTimerCreate("timer", pdMS_TO_TICKS(interval), pdTRUE, 0, onTimer); // 名称、周期、自动重新加载、计时器 ID、回调
 -   if (timerHandle != NULL) { 
 -     xTimerStart(timerHandle, 0); 
 -   } 
 - 
 - } 
 - 
 - void loop() { 
 -   
 -  
 -     //Serial.printf("%02d:%02d:%02d\n", hrs, minutes, sec); 
 - 
 -     //Serial.print("months : "); 
 -     //Serial.println(monthsOfYear[months]); 
 -     //Serial.print("day : "); 
 -     //Serial.println(daysOfWeek[days]); 
 - 
 -     //按钮读取// 
 -    // if (inp1 == HIGH ){ 
 -     //Serial.print("35"); 
 -     //} 
 -     //页面读取// 
 -     //Serial.print("PG: "); 
 -     //Serial.println(page); 
 -     //Serial.print("change: "); 
 -     //Serial.println(pageChange); 
 -     //Serial.print("Refresh: "); 
 -     //Serial.打印(pageRefresh);
 -       延迟(1000);
 - 
 - } 
 - 
 - void input(void *pvParameters){ 
 -   
 -   while(1){ 
 -   inp1=digitalRead(b_1);
 -   inp2=digitalRead(b_2);
 -   inp3=digitalRead(b_3);
 -   inp4=digitalRead(b_4);
 - 
 -   if(inp1==HIGH && pageChange ==true)
 -   { 
 -     pageChange=false; 
 -     pageRefresh=true; 
 -     page++; //下一页
 -   } 
 -   
 -   if(inp2==HIGH && pageChange ==true)
 -   { 
 -     pageChange=false; 
 -     pageRefresh=true; 
 -     page--; //上一页
 -   } 
 -   
 -   if(page ==1 && mainMenu == true&& inp3==HIGH && pageChange ==true && wait==false)//菜单选择控制
 -   { 
 -     pageRefresh=true;
 -      selectedOption = (selectedOption + 1) % menuCount; 
 -      Serial.println(selectedOption); 
 -       Serial.println("main"); 
 -   } 
 -   
 -   if(inp4==HIGH && pageChange ==true && mainMenu == true && page == 1 && wait== false) //菜单进入控制
 -   { 
 -     wait = true; 
 -     pageChange = false; 
 -     mainMenu = false; 
 -     subMenu= true; 
 -     pageRefresh=true; 
 - 
 -     Serial.print("INP4"); 
 - 
 -   } 
 - 
 -   if(selectedOption == 1 && inp3==HIGH && subMenu==true && mainMenu==false&& wait==false) //时间设置菜单控制
 -   { 
 -     
 -     timePage =false; 
 -     pageRefresh=true; 
 -     //Serial.print("按下时钟菜单"); 
 -     timeMenu_Select = (timeMenu_Select + 1) % timeMenu ; 
 -      //Serial.println(timeMenu_Select); 
 -   } 
 - 
 -   //页码处理程序
 -   page>3?page=0:page<0?page=3:page=page; 
 -   vTaskDelay(200); 
 -   } 
 - } 
 - 
 - 
 - void tft_page(void *pvParameters) 
 - { 
 -   while(1) 
 -   { 
 -     if(page==0 && mainMenu == true) // main 
 -     { 
 -         if(pageRefresh==true){ 
 -           tft.fillScreen(TFT_BLACK); 
 -           pageRefresh= false; 
 -           Serial.print("refresh"); 
 -         } 
 -         if(pageRefresh==false){ 
 -           //Page 
 -             tft.setTextColor(TFT_WHITE, TFT_BLACK); 
 -             // years // 
 -               tft.setTextSize(3); 
 -               tft.setCursor(85, 73); //xy 
 -               tft.printf("%04d\n", yrs); 
 -             // date/month // 
 -               tft.setTextSize(3); 
 -               tft.setCursor(75,101); //xy 
 -               tft.printf("%02d/%02d\n", days, months); 
 -             // 时间
 -               tft.setTextSize(4); 
 -               tft.setCursor(28, 130); //xy 
 -               tft.printf("%02d:%02d:%02d\n", hrs, minutes, sec); 
 -               tft.setTextSize(3); 
 -             // 天
 -               textWidth = tft.textWidth(daysOfWeek[daysOfWeekCount]); 
 -               x = (screenW - textWidth) / 2; 
 -               tft.setCursor(x, 165); //xy 
 -               tft.print(daysOfWeek[daysOfWeekCount]); 
 -               textWidth = tft.textWidth(monthsOfYear[months]); 
 -             // 月
 -               x = (screenW - textWidth) / 2; 
 -               tft.setCursor(x, 193); //xy 
 -               tft.打印(monthsOfYear[months]); 
 -             vTaskDelay(100);
 -             pageChange=true;
 -         }   
 -     }   
 -     else if(page==1 && mainMenu == true && wait==false) //菜单
 -     { wait ==true; 
 -         if(pageRefresh==true){ 
 -           tft.fillScreen(TFT_BLACK); 
 -           pageRefresh= false; 
 -         } 
 -         if(pageRefresh==false){ 
 -           //isi 
 -              tft.setTextSize(2); 
 -                 const int menuItemWidth = 200; //每个菜单项的宽度
 -                 const int menuItemHeight = 50; //每个菜单项的高度
 -                 const int menuItemSpacing = 10; //菜单项之间的间距
 - 
 -                 int totalMenuHeight = menuCount * (menuItemHeight + menuItemSpacing) - menuItemSpacing; 
 -                 int menuStartY = (tft.height() - totalMenuHeight) / 2; 
 - 
 -                 for (int i = 0; i < menuCount; i++) { 
 -                   
 -                   int x = (tft.width() - menuItemWidth) / 2; 
 -                   int y = menuStartY + i * (menuItemHeight + menuItemSpacing); 
 - 
 -                   int xText = (screenW - tft.textWidth(menuText[i]))/ 2; 
 -                   
 - 
 -                   if (i == selectedOption) { 
 -                     tft.fillRoundRect(x, y, menuItemWidth, menuItemHeight, 10, TFT_YELLOW); 
 -                     tft.setTextColor(TFT_BLACK); 
 -                   } else { 
 -                     tft.drawRoundRect(x, y, menuItemWidth, menuItemHeight, 10, TFT_WHITE); 
 -                     tft.setTextColor(TFT_WHITE); 
 -                   } 
 - 
 -                   tft.drawString(String(menuText[i]) , xText, y + 15); 
 -                      // Serial.println("wifiSub"); 
 -                 } 
 -             
 -             pageChange=true; 
 -           
 -         }   
 -         vTaskDelay(100); 
 -       wait== false; 
 -     } 
 -     else if(page==2 && mainMenu == true) //花
 -     { 
 -         if(pageRefresh==true){ 
 -           tft.fillScreen(TFT_BLACK); 
 -           pageRefresh= false; 
 -         } 
 -         if(pageRefresh==false){ 
 - 
 -           // isi 
 -             tft.pushImage(0,0,screenW,screenH,Flower_240x280); 
 -           vTaskDelay(100); 
 -           pageChange=true; 
 -         }   
 - 
 -     } 
 -     else if(page==3 && mainMenu == true) //颜色
 -     { 
 -         if(pageRefresh==true){ 
 -           tft.fillScreen(TFT_BLACK); 
 -           pageRefresh= false; 
 -         } 
 -         if(pageRefresh==false){ 
 - 
 -           // isi 
 -             tft.fillScreen(TFT_PINK); 
 -           vTaskDelay(100); 
 -           pageChange=true; 
 -         }   
 - 
 -     } 
 - 
 -     //子菜单
 -     if(mainMenu == false && subMenu ==true &&selectedOption == 0 ){ //亮度控制
 -         String text = "Brightness"; 
 -         if(pageRefresh==true){ 
 -           tft.fillScreen(TFT_BLACK); 
 -           pageRefresh= false; 
 -         } 
 -         if(pageRefresh==false){ 
 -           //isi 
 -             tft.setTextColor(TFT_WHITE, TFT_BLACK); 
 -             tft.setTextSize(3); 
 -             x = (screenW - tft.textWidth(text)) / 2; 
 -             tft.setCursor(x,100); 
 -             tft.print(text); 
 -             tft.setTextSize(3); 
 -             x = screenW/2; 
 -             tft.setCursor(x,180); 
 -             tft.print(Level); 
 -               if(inp1 == HIGH){ //增加亮度
 -                   if(Level < 6){ 
 -                   Level++;
 -                   亮度 = mapRange(Level, 1, 6, 20 ,255); 
 -                   analogWrite(BL, 亮度); 
 -                   vTaskDelay(100);}} 
 -                   
 -                   
 -               if(inp2 == HIGH){//降低亮度
 -                 if(Level > 1){ 
 -                 Level--;
 -                 亮度 = mapRange(Level, 1, 6, 20 ,255); 
 -                 analogWrite(BL, 亮度); 
 -                 vTaskDelay(100);}} 
 -                 vTaskDelay(100); 
 - 
 -               if(inp4 == HIGH && wait==false){//返回主
 -                 串口。打印(“哎哟”);
 -              mainMenu=true; 
 -              subMenu=false; 
 -              pageChange=true; 
 -              page=1; 
 -              pageRefresh=true; 
 -              vTaskDelay(100); 
 -               } 
 -               wait=false; 
 -            
 -         }   
 -         
 -          
 -     } 
 -     if(selectedOption == 1 && mainMenu == false && subMenu ==true ){ // 时间控制
 -   
 -             if(pageRefresh==true){ 
 -                   tft.fillScreen(TFT_BLACK); 
 -               
 -                   pageRefresh= false; 
 -                 } 
 -                 if(pageRefresh==false){ 
 -                   timePage ==false; 
 -                   // isi 
 -                     const int timeMenuWidth = 180; // 每个菜单项的宽度
 -                     const int timeMenuHeight = 60; // 每个菜单项的高度
 -                     const int timeMenuSpacing = 10; // 菜单项之间的间距
 -                     
 -                     
 -                     String TimeMenuList[timeMenu]={"Clock","Date","Back"}; 
 - 
 -                     int totalMenuHeight = timeMenu * (timeMenuHeight + timeMenuSpacing) - timeMenuSpacing; 
 -                         int menuStartY = (tft.高度( - 总菜单高度)/ 2;
 - 
 -                         对于(int i = 0; i < timeMenu; i ++){ 
 -                           int x =(tft.width( - timeMenuWidth)/ 2; 
 -                           int y = menuStartY + i *(timeMenuHeight + timeMenuSpacing);
 - 
 -                           如果(i == timeMenu_Select){ 
 -                             tft.fillRoundRect(x,y,timeMenuWidth,timeMenuHeight,10,TFT_YELLOW); 
 -                             tft.setTextColor(TFT_BLACK); 
 -                           } else { 
 -                             tft.drawRoundRect(x,y,timeMenuWidth,timeMenuHeight,10,TFT_WHITE); 
 -                             tft.setTextColor(TFT_WHITE); 
 -                           } 
 - 
 -                           int xText =(screenW - tft.textWidth(TimeMenuList [i]))/ 2; 
 -                           tft.drawString(String(TimeMenuList [i]),xText,y + 15); 
 -                             // Serial.println("wifiSub"); 
 -                         } 
 -                     vTaskDelay(100); 
 -                     if(inp4==HIGH && wait==false && timeMenu_Select==0){ // 到时间
 -                       wait=true; 
 -                       subMenu=false; 
 -                       pageRefresh=true; 
 -                       timePage=true; 
 -                       Serial.println("到时间"); 
 -                     } 
 -                     if(inp4==HIGH && wait==false && timeMenu_Select==1){ // 到日期
 -                       wait=true; 
 -                       subMenu=false; 
 -                       pageRefresh=true; 
 -                       timePage=true; 
 -                       Serial.println("到日期"); 
 -                     } 
 -                     if(inp4 == HIGH && wait==false && timeMenu_Select==2 ){ //返回主
 -                         Serial.print("Ouch"); 
 -                     mainMenu=true; 
 -                     subMenu=false; 
 -                     pageChange=true; 
 -                     page=1; 
 -                     pageRefresh=true; 
 -                     vTaskDelay(100); 
 -                       } 
 -                     wait=false; 
 -                     
 -                 } 
 -             } 
 - 
 -     if(selectedOption == 2 && mainMenu == false && subMenu ==true ){ //设置
 -       
 -         if(pageRefresh==true){ 
 -               tft.fillScreen(TFT_BLACK); 
 -               pageRefresh= false; 
 -             } 
 -             if(pageRefresh==false){ 
 -               // isi 
 -                 tft.pushImage(0,0,screenW,screenH,MINGO); 
 -                 vTaskDelay(100);
 -                 if(inp4 == HIGH && wait==false){//返回主
 -                 串口。打印(“哎哟”);
 -              mainMenu=true;
 -              subMenu=false;
 -              pageChange=true;
 -              page=1;
 -              pageRefresh=true;
 -              vTaskDelay(100);
 -               } 
 -               wait=false;
 -               
 -             }   
 -     } 
 -     if(selectedOption == 3 && mainMenu == false && subMenu ==true){//关于 esp32 
 - 
 -           if(pageRefresh==true){ 
 -                 tft.fillScreen(TFT_BLACK);
 -                 pageRefresh=false;
 -               } 
 -               if(pageRefresh==false){ 
 -                 // isi 
 -                 const char *message[] = {"ESP32-WROOM","ESP32-D0WDQ6","Chip-v4.4.3","ID:DCC84E9EF0C8","Speed-240 Mhz","Flash:4.19 MB","F-Speed:80 Mhz","Flash Mode:0","F-Used:674.06 KB","Cores:2","RAM:256 KB"}; 
 -                 menuChange=false; 
 -                 tft.setTextSize(2); 
 -                 tft.setTextColor(TFT_WHITE, TFT_BLACK); 
 -                 textWidth = tft.textWidth(message[0]); 
 -                 x = (screenW - textWidth) / 2; 
 -                 tft.setCursor(x, 27); //xy 
 -                 tft.print(message[0]); 
 - 
 -                 textWidth = tft.textWidth(message[1]); 
 -                 x = (屏幕宽 - textWidth) / 2; 
 -                 tft.setCursor(x, 45); //xy 
 -                 tft.print(message[1]); 
 - 
 -                 textWidth = tft.textWidth(message[2]); 
 -                 x = (屏幕宽 - textWidth) / 2; 
 -                 tft.setCursor(x, 62); //xy 
 -                 tft.print(message[2]); 
 - 
 -                 textWidth = tft.textWidth(message[3]); 
 -                 x = (屏幕宽 - textWidth) / 2; 
 -                 tft.setCursor(x, 79); //xy 
 -                 tft.print(message[3]); 
 - 
 -                 textWidth = tft.textWidth(message[4]); 
 -                 x = (屏幕宽 - textWidth) / 2; 
 -                 tft.setCursor(x, 95); //xy 
 -                 tft.print(message[4]); 
 - 
 -                 textWidth = tft.textWidth(message[5]); 
 -                 x = (屏幕宽 - textWidth) / 2; 
 -                 tft.setCursor(x, 112); //xy 
 -                 tft.print(message[5]); 
 - 
 -                 textWidth = tft.textWidth(message[6]); 
 -                 x = (屏幕宽 - textWidth) / 2; 
 -                 tft.setCursor(x, 128); //xy 
 -                 tft.print(message[6]); 
 - 
 -                 textWidth = tft.文本宽度(消息[7]); 
 -                 x =(屏幕宽 - 文本宽度)/ 2;
 -                 tft.setCursor(x, 145); //xy 
 -                 tft.print(message[7]); 
 - 
 -                 textWidth = tft.textWidth(message[8]); 
 -                 x = (屏幕宽 - textWidth) / 2; 
 -                 tft.setCursor(x, 163); //xy 
 -                 tft.print(message[8]); 
 - 
 -                 textWidth = tft.textWidth(message[9]); 
 -                 x = (屏幕宽 - textWidth) / 2; 
 -                 tft.setCursor(x, 180); //xy 
 -                 tft.print(message[9]); 
 -                 
 -                 textWidth = tft.textWidth(message[10]); 
 -                 x = (屏幕宽 - textWidth) / 2; 
 -                 tft.setCursor(x, 198); //xy 
 -                 tft.print(message[10]); 
 - 
 -                   vTaskDelay(100); 
 -                   if(inp4 == HIGH && wait==false){ //返回主
 -                 串口。打印("Ouch"); 
 -              mainMenu=true; 
 -              subMenu=false; 
 -              pageChange=true; 
 -              page=1; 
 -              pageRefresh=true; 
 -              vTaskDelay(100); 
 -               } 
 -               wait=false; 
 -                 
 -               }   
 -     } 
 - 
 -           //时钟设置页面
 -           if(timeMenu_Select==0 && mainMenu == false && timePage ==true ){ //设置
 - 
 -             if(pageRefresh==true){ 
 -                   tft.fillScreen(TFT_BLACK); 
 -                   pageRefresh= false; 
 -                 } 
 -                 if(pageRefresh==false){ 
 -                  
 -                   // isi 
 -                   int menuColumnCount = 3; 
 -                   int menuRowCount = 1; 
 - 
 -                   const int menuItemSize = 60; //菜单项的较小尺寸
 -                   const int menuItemSpacing = 10; //菜单项之间的空间
 -                   const int menuItemCornerRadius = 5; //圆角半径
 -                   const int highlightsBorderWidth = 3; // 高亮边框的宽度
 - 
 -                   int clockMenuCount = menuColumnCount*menuRowCount; 
 -                   
 - 
 -                     int clockNOW[] = {hrs,minute,sec}; 
 -                   
 -                       int totalMenuWidth = menuColumnCount * (menuItemSize + menuItemSpacing) - menuItemSpacing; 
 -                       int totalMenuHeight = menuRowCount * (menuItemSize + menuItemSpacing) - menuItemSpacing; 
 - 
 -                       int menuStartX = screenW/2 - totalMenuWidth / 2; 
 -                       int menuStartY = screenH/2 - totalMenuHeight / 2; 
 - 
 -                       for (int i = 0; i < clockMenuCount; i++) { 
 -                         int row = i / menuColumnCount;
 -                         int col = i % menuColumnCount; 
 - 
 -                         int x = menuStartX + col * (menuItemSize + menuItemSpacing); 
 -                         int y = menuStartY + row * (menuItemSize + menuItemSpacing); 
 - 
 -                         bool isSelected = (i == clockSelect); 
 -                               tft.setTextSize(2); 
 -                         if (isSelected) { 
 -                           // 在菜单项周围绘制一个高亮圆角矩形轮廓
 -                           tft.drawRoundRect(x - highlightsBorderWidth, y - highlightsBorderWidth, menuItemSize + 2 * highlightsBorderWidth, menuItemSize + 2 * highlightsBorderWidth, menuItemCornerRadius + highlightsBorderWidth, TFT_ORANGE); 
 -                           tft.setTextColor(TFT_ORANGE,TFT_BLACK); 
 -                           
 -                         } else { 
 -                           tft.drawRoundRect(x, y, menuItemSize, menuItemSize, menuItemCornerRadius, TFT_WHITE); 
 -                           tft.setTextColor(TFT_WHITE,TFT_BLACK); 
 -                         } 
 - 
 -                     // 绘制菜单项徽标和文本
 -                       tft.drawString(String(clockNOW[i]), x + 15, y + menuItemSize / 2 - 5); 
 -                           } 
 -                     vTaskDelay(200); 
 -                     
 -                     if(inp1==HIGH){ 
 -                         Serial.println("HIGH 1"); 
 -                         if(clockSelect == 0){ 
 -                             hrs++; 
 -                             if(hrs>23){ 
 -                               hrs=0; 
 -                             } 
 -                         } 
 -                         if(clockSelect == 1){ 
 -                           minutes++; 
 -                           if(minute > 59){ 
 -                             minutes=0; 
 -                           } 
 -                         } 
 -                         if(clockSelect == 2){ 
 -                           sec=59; 
 -                         
 -                         } 
 -                     } 
 -                     if(inp2==HIGH){ 
 -                         Serial.println("HIGH 2"); 
 -                         if(clockSelect == 0){ 
 -                             hrs--; 
 -                             if(hrs<0){ 
 -                               hrs=23; 
 -                             } 
 -                         } 
 -                         if(clockSelect == 1){
 -                           分钟--; 
 -                             if(分钟 < 0){
 -                                 分钟=59; 
 -                             } 
 -                         }
 -                         if(clockSelect == 2){ 
 -                           sec = 0; 
 -                         } 
 -                     } 
 -                     if(inp3==HIGH && wait==false){ 
 -                                 pageRefresh=true; 
 -                                 Serial.print("按下时钟选择"); 
 -                                 clockSelect = (clockSelect + 1) % 3; 
 -                                 Serial.println(clockSelect); 
 -                                 vTaskDelay(100); 
 -                     } 
 -                     if(inp4 == HIGH && wait==false ){ //返回主
 -                         Serial.print("哎哟"); 
 -                     mainMenu=true; 
 -                     subMenu=false; 
 -                     timePage=false; 
 -                     pageChange=true; 
 -                     page=1; 
 -                     pageRefresh=true; 
 -                     vTaskDelay(100); 
 -                       } 
 -              
 -                   wait=false; 
 -                   
 -                 }   
 -         } 
 - 
 -         if(timeMenu_Select==1 && mainMenu == false && timePage ==true ){ //设置
 -           
 -             if(pageRefresh==true){ 
 -                   tft.fillScreen(TFT_BLACK); 
 -                   pageRefresh= false; 
 -                 } 
 -                 if(pageRefresh==false){ 
 -                    tft.setTextSize(3); 
 -                 const int menuItemWidth = 200; // 每个菜单项的宽度
 -                 const int menuItemHeight = 50; // 每个菜单项的高度
 -                 const int menuItemSpacing = 10; // 菜单项之间的间距
 - 
 -             
 - 
 -                 const int dateOption = 3; 
 -                 int date_num[]={days,months,yrs}; 
 - 
 -                 int totalMenuHeight = dateOption * (menuItemHeight + menuItemSpacing) - menuItemSpacing; 
 -                 int menuStartY = (tft.height() - totalMenuHeight) / 2; 
 - 
 -                 for (int i = 0; i < dateOption; i++) { 
 -                   
 -                   int x = (tft.width() - menuItemWidth) / 2; 
 -                   int y = menuStartY + i * (menuItemHeight + menuItemSpacing);
 - 
 -                   
 -                   
 - 
 -                   如果(i == dateSelect){ 
 -                     tft.fillRoundRect(x,y,menuItemWidth,menuItemHeight,10,TFT_YELLOW);
 -                     tft.setTextColor(TFT_BLACK);
 -                   } else { 
 -                     tft.drawRoundRect(x,y,menuItemWidth,menuItemHeight,10,TFT_WHITE);
 -                     tft.setTextColor(TFT_WHITE);
 -                   } 
 - 
 -                   tft.drawString(String(date_num [i]),x + 10,y + 15);
 -                      // Serial.println("wifiSub"); 
 -                 } 
 -                     vTaskDelay(200); 
 -                     
 -                   wait=false; 
 -                   if(inp1 ==HIGH&&wait==false){ 
 -                     if(dateSelect==0){ 
 - 
 -                       days++; 
 -                       if(days>days_Max){ 
 -                         days=1; 
 -                       } 
 -                     } 
 -                     if(dateSelect==1){ 
 -                       months++; 
 -                       if(months>12){ 
 -                         months=1; 
 -                       } 
 -                     } 
 -                     if(dateSelect==2){ 
 -                       yrs++; 
 -                       
 -                     } 
 -                   } 
 -                   if(inp2 ==HIGH&&wait==false) { 
 -                     if(dateSelect==0){ 
 -                       days--; 
 -                       if(days < 1){ 
 -                         days=days_Max; 
 -                       } 
 -                     } 
 -                     if(dateSelect==1){ 
 -                       months--; 
 -                       if(months<1){ 
 -                         months=12; 
 -                       } 
 -                     } 
 -                     if(dateSelect==2){ 
 -                       yrs--; 
 -                  
 -                       if (yrs <0){ 
 - 
 -                         yrs=9999; 
 -                       } 
 -                     } 
 -                   } 
 -                   if(inp3 ==HIGH &&wait==false){ 
 -                        pageRefresh=true; 
 -                                 Serial.print("按下日期选择"); 
 -                                 dateSelect = (dateSelect + 1) % 3; 
 -                                 Serial.println(dateSelect); 
 -                                 vTaskDelay(100); 
 -                   } 
 -                   if(inp4 ==HIGH && wait==false){ 
 -                     Serial.print("哎哟"); 
 -                     mainMenu=true; 
 -                     subMenu=false; 
 -                     timePage 
 -                     =false; pageChange=true 
 -                     ; page=1; 
 -                     pageRefresh=true; 
 -                     vTaskDelay(100); 
 -                   } 
 -                   
 -                 }   
 -         } 
 -  
 -   } void v_Read(void *pvParameters) { 
 - while (1) {   uint32_t Vbatt = 0;   for(int i = 0; i < 16; i++) {
 - 
 - 
 - 
 - 
 - 
 - 
 - 
 -     Vbatt = Vbatt + analogReadMilliVolts(v_R); // 带校正的 ADC    
 -   } 
 -   float Vbattf = 2 * Vbatt / 16 / 1000.0; // 衰减率 1/2,mV --> V 
 -   Serial.println(Vbattf, 3);
 -   延迟(1000); 
 - } 
 - 
 - 
 - } 
 - void onTimer(TimerHandle_t xTimer) { 
 -     sec++; 
 -     
 -     if (sec > 59) { 
 -         sec = 0;
 -         分钟++; 
 -         if (minute > 59) {
 -             分钟 = 0; 
 -             hrs++; 
 -             if (hrs > 23) { 
 -                 hrs = 0; 
 -                 days++; 
 -                 pageRefresh = true; 
 -                 if (months == 2) { 
 -                         if (yrs % 4 == 0) { 
 -                             days_Max = 29; 
 -                         } else { 
 -                             days_Max = 28; 
 -                         } 
 -                     } else if (months == 4 || months == 6 || months == 9 || months == 11) { 
 -                         days_Max = 30; 
 -                       } else { 
 -                         days_Max = 31; 
 -                       } 
 -                 if (days > days_Max) { 
 -                     days = 1;     months 
 -                     ++; 
 -                     if (months > 12) { 
 -                         months = 1; 
 -                         yrs++; 
 -                     } 
 -                     
 -                 } 
 -                
 -             } 
 -         }     daysOfWeekCount = (days + (13 * (months + 1)) / 5 + yrs % 100 + (yrs % 100) / 4 + (yrs / 100) / 4 + 5 * (yrs / 100)) % 7;     daysOfWeekCount = (daysOfWeekCount + 6) % 7; }
 
  复制代码
  
 
 |