用RP2040-Touch-LCD-1.28制作一个手表_添加背景

做的这个手表目前还是纯色背景,这不给力。
可以将图片转化为数组导进去,作为背景。效果大概这样:在这里插入图片描述
第一、准备软件把图转成数组
字模提取V2.2 看来是不能整彩色的图片了。所以参考了他的推荐
添加链接描述

可以把彩色bmp图片转成数组。
百度网盘:
添加链接描述
mmrp
在这里插入图片描述
我尝试了导入bmp格式的图片,他的输出参数选 C语言数组,水平扫描,16位真色彩,240×240,就可以了,点击保存。
得到的数组需要复制到工程中 ImageData.cpp 中,并且在ImageData.h 中要声明。
在这里插入图片描述

在这里插入图片描述

第二、改写部分程序
这个时候,每次刷新的底图就不是全黑的了,要把 Paint_Clear(BLACK); 改成 Paint_DrawImage(PicSeqSelec(iPicSeq),0,0,240,240);
其中PicSeqSelec(int )函数是切换图片的,我导入了8张图片。

注意:导入的每个数组,最后数组是 ','结尾的,虽然这样写在c++里报错,但是在arduino好像必须这么写。

这是改好的程序 RP2040-Touch-LCD-1.28.ino

#include "LCD_Test.h"

// 【计时
#define TIMER_INTERRUPT_DEBUG         1
#define _TIMERINTERRUPT_LOGLEVEL_     4
#define TIMER0_INTERVAL_MS        1000
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "RPi_Pico_TimerInterrupt.h"
RPI_PICO_Timer ITimer0(0);
// 计时】


void Touch_INT_callback();
uint8_t flag = 0;
int Hour = 22;
int Min = 22;
int Sec = 22;
uint8_t iLight_restore = 50;
uint8_t iLight = 50;
uint32_t LTIMSE = 0;
UWORD *BlackImage;
volatile int Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro = 0;

unsigned int tim_count = 0;
float acc[3], gyro[3];
const float conversion_factor = 3.3f / (1 << 12) * 3;
String comTemp = "";
char strTemp[8]={'\0'};
char temp;
int iCount = 0;

uint8_t iPicSeq=0;

const unsigned char* PicSeqSelec(uint8_t iSeq)
{
  const unsigned char* p = NULL;

  if(iSeq==0)
  {
      p = gImage_xh2;
  }
  else if(iSeq==1)
  {
      p = gImage_qinglong;
  }
  else if(iSeq==2)
  {
      p = gImage_baihu;
  }
  else if(iSeq==3)
  {
      p = gImage_zhuque;
  }
  else if(iSeq==4)
  {
      p = gImage_xuanwu;
  }
  else if(iSeq==5)
  {
      p = gImage_bagua;
  }
  else if(iSeq==6)
  {
      p = gImage_sepin;
  }
  else if(iSeq==7)
  {
      p = gImage_haimianbaobao;
  }
  return p;
}


bool TimerHandler0(struct repeating_timer *t)
{ 
  Sec++;
  if (Sec > 59) {
    Sec = 0;
    Min++;
  }
  if (Min > 59) {
    Min = 0;
    Hour++;
  }
  if (Hour > 23) {
    Hour = 0;
  }
  return true;
}



void SerialEvent()
{
  while(Serial.available())
  {
    temp= char(Serial.read());
    strTemp[iCount++]=temp;
    comTemp += temp;
    delay(2);
    int len = comTemp.length();
    if(len>=8)
    {
      Hour = (strTemp[0]-0x30)*10+(strTemp[1]-0x30);
      Min = (strTemp[3]-0x30)*10+(strTemp[4]-0x30);
      Sec = (strTemp[6]-0x30)*10+(strTemp[7]-0x30);
      Serial.print(Hour);
      Serial.print(Min);
      Serial.print(Sec);
      comTemp="";
      iCount=0;
    }

  }

}

void MyTickgo() {

  if (iLight > 0) {
    
    Paint_DrawImage(PicSeqSelec(iPicSeq),0,0,240,240);
    //Paint_Clear(BLACK);
    if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 0) {
      Paint_DrawString_EN(50, 40, "Run", &Font24, BLACK, WHITE);

      //电池 3.4v到4.0V
      uint16_t val = analogRead(BAT_ADC_PIN);
      double batper = val * conversion_factor;
      batper = (batper - 3.4) / 0.6 * 100.0;
      if (batper > 100) {
        batper = 100;
      } else if (batper < 0) {
        batper = 0;
      }
      Paint_DrawNum(110, 40, batper, &Font24, 1, WHITE, BLACK);
      if (batper >= 100) {
        Paint_DrawString_EN(195, 40, "%", &Font24, BLACK, WHITE);
      } else {
        Paint_DrawString_EN(175, 40, "%", &Font24, BLACK, WHITE);
      }
      double result = DEC_ADC_Read() * conversion_factor;
      Paint_DrawNum(110, 65, result, &Font24, 1, WHITE, BLACK);
    } else if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 5) {
      //Paint_DrawString_EN(50, 40, "gyro", &Font24, BLACK, WHITE);
      //myTuoLuo();
      Paint_DrawImage(PicSeqSelec(iPicSeq),0,0,240,240);

    } else {
      //Paint_DrawRectangle(0, 160, 120, 240, 0X2595, DOT_PIXEL_2X2, DRAW_FILL_FULL);
      //Paint_DrawRectangle(121, 160, 240, 240, 0X6634, DOT_PIXEL_2X2, DRAW_FILL_FULL);
      Paint_DrawString_EN(60, 170, "-", &Font24, BLACK, WHITE);
      Paint_DrawString_EN(180, 170, "+", &Font24, BLACK, WHITE);
      if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 1) {
        Paint_DrawString_EN(50, 40, "Hour", &Font24, BLACK, WHITE);
      } else if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 2) {
        Paint_DrawString_EN(50, 40, "Min", &Font24, BLACK, WHITE);
      } else if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 3) {
        Paint_DrawString_EN(50, 40, "Sec", &Font24, BLACK, WHITE);
      } else if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 4) {
        Paint_DrawString_EN(50, 40, "Light", &Font24, BLACK, WHITE);
        Paint_DrawNum(110, 65, iLight, &Font24, 1, WHITE, BLACK);
      }
    }

    if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro != 5) {
      Paint_DrawNum(20, 88, Hour, &Font64, 0, WHITE, BLACK);
      Paint_DrawString_EN(80, 88, ":", &Font64, BLACK, WHITE);
      Paint_DrawNum(108, 88, Min, &Font64, 0, WHITE, BLACK);
      Paint_DrawString_EN(170, 88, ":", &Font64, BLACK, WHITE);
      Paint_DrawNum(198, 125, Sec, &Font24, 0, WHITE, BLACK);
    } else {
    }
    SerialEvent();

    LCD_1IN28_Display(BlackImage);

  }
}

void myTuoLuo()
{
  //uint16_t result;
  //result = DEC_ADC_Read();
  QMI8658_read_xyz(acc, gyro, &tim_count);
  Paint_DrawString_EN(40, 100, "ACC_X=", &Font16, BLACK, WHITE);
  Paint_DrawString_EN(40, 120, "ACC_Y=", &Font16, BLACK, WHITE);
  Paint_DrawString_EN(40, 140, "ACC_Z=", &Font16, BLACK, WHITE);
  Paint_DrawString_EN(40, 160, "GYR_X=", &Font16, BLACK, WHITE);
  Paint_DrawString_EN(40, 180, "GYR_Y=", &Font16, BLACK, WHITE);
  Paint_DrawString_EN(40, 200, "GYR_Z=", &Font16, BLACK, WHITE);

  Paint_DrawNum(120, 100, acc[0], &Font16, 2, WHITE, BLACK);
  Paint_DrawNum(120, 120, acc[1], &Font16, 2, WHITE, BLACK);
  Paint_DrawNum(120, 140, acc[2], &Font16, 2, WHITE, BLACK);
  Paint_DrawNum(120, 160, gyro[0], &Font16, 2, WHITE, BLACK);
  Paint_DrawNum(120, 180, gyro[1], &Font16, 2, WHITE, BLACK);
  Paint_DrawNum(120, 200, gyro[2], &Font16, 2, WHITE, BLACK);
  //Paint_DrawNum(40, 80, result * conversion_factor, &Font16, 2, WHITE, BLACK);

}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  if (DEV_Module_Init() != 0)
    Serial.println("GPIO Init Fail!");
  else
    Serial.println("GPIO Init successful!");

  LCD_1IN28_Init(HORIZONTAL);
  DEV_SET_PWM(0);
  LCD_1IN28_Clear(WHITE);
  DEV_SET_PWM(50);
  UDOUBLE Imagesize = LCD_1IN28_HEIGHT * LCD_1IN28_WIDTH * 2;
  //UWORD *BlackImage;
  if ((BlackImage = (UWORD *)malloc(Imagesize)) == NULL) {
    Serial.println("Failed to apply for black memory...");
    exit(0);
  }
  // /*1.Create a new image cache named IMAGE_RGB and fill it with white*/
  Paint_NewImage((UBYTE *)BlackImage, LCD_1IN28.WIDTH, LCD_1IN28.HEIGHT, 0, WHITE);
  Paint_SetScale(65);
  Paint_Clear(WHITE);
  Paint_SetRotate(ROTATE_0);
  Paint_Clear(WHITE);
  // /* GUI */
  Serial.println("drawing...\r\n");
  // /*2.Drawing on the image*/

  ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0);
#if 1

  Paint_DrawLine(35, 35, 205, 35, MAGENTA, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  Paint_DrawLine(205, 35, 205, 205, MAGENTA, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  Paint_DrawLine(35, 205, 205, 205, MAGENTA, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  Paint_DrawLine(35, 35, 35, 205, MAGENTA, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
  //Paint_DrawString_EN(50, 100, "HAHA", &Font20, 0x000f, 0xfff0);

  //Paint_DrawString_EN(50, 161, "WaveShare", &Font16, RED, WHITE);

  Paint_DrawString_CN(54, 72, "恭\n", &Font24CN, BLUE, WHITE);
  Paint_DrawString_CN(86, 72, "喜\n", &Font24CN, BLUE, WHITE);
  Paint_DrawString_CN(118, 72, "發\n", &Font24CN, BLUE, WHITE);
  Paint_DrawString_CN(150, 72, "财\n", &Font24CN, BLUE, WHITE);
  // /*3.Refresh the picture in RAM to LCD*/
  
  Paint_DrawImage(PicSeqSelec(iPicSeq),0,0,240,240);
  LCD_1IN28_Display(BlackImage);
  DEV_Delay_ms(200);

#endif

#if 1

  QMI8658_init();
  CST816S_init(CST816S_Gesture_Mode);
  DEV_KEY_Config(Touch_INT_PIN);
  attachInterrupt(Touch_INT_PIN, &Touch_INT_callback, RISING);
  Serial.println("QMI8658_init\r\n");
  MyTickgo();
 
#endif

#if 0
flag = 1;
    Paint_Clear(WHITE);
    //Paint_DrawRectangle(0, 00, 240, 47, 0X2595, DOT_PIXEL_2X2, DRAW_FILL_FULL);
    //Paint_DrawString_EN(60, 30, "Touch test", &Font16, WHITE, BLACK);
    LCD_1IN28_Display(BlackImage);
    CST816S_init(CST816S_Point_Mode);
    while (true)
    {
        if (flag == 1)
        {
            Paint_DrawPoint(Touch_CTS816.x_point, Touch_CTS816.y_point, BLUE, DOT_PIXEL_1X1, DOT_FILL_AROUND);
            LCD_1IN28_DisplayWindows(Touch_CTS816.x_point, Touch_CTS816.y_point, Touch_CTS816.x_point + 1, Touch_CTS816.y_point + 1, BlackImage);
            Serial.printf("X:%d Y:%d\r\n", Touch_CTS816.x_point, Touch_CTS816.y_point);
            flag = 0;
        }
        DEV_Delay_us(500);
    }
#endif
}


void loop()
{
  MyTickgo();
}

void Touch_INT_callback() {

  uint8_t gesture = CST816S_Get_Gesture();
  if (gesture == CST816S_Gesture_Long_Press)
  {
    if(Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro!=1)
    {
      Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro=1;
    }
    else
    {
      Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro=0;
    }

    // if(Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro==5)
    // {
    //   Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro=0;
    // }
    // else
    // {
    //   Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro=5;
    // }
  }
  else if(gesture == CST816S_Gesture_Click)
  {
      CST816S mypoint = CST816S_Get_Point();

      if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 0) {
        Paint_DrawString_EN(50, 40, "Run", &Font24, WHITE, BLACK);
      } else if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 1) {
        Paint_DrawString_EN(50, 40, "Hour", &Font24, WHITE, BLACK);
        Paint_DrawString_EN(60, 170, "-", &Font24, WHITE, BLACK);
        Paint_DrawString_EN(180, 170, "+", &Font24, WHITE, BLACK);
      } else if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 2) {
        Paint_DrawString_EN(50, 40, "Min", &Font24, WHITE, BLACK);
        Paint_DrawString_EN(60, 170, "-", &Font24, WHITE, BLACK);
        Paint_DrawString_EN(180, 170, "+", &Font24, WHITE, BLACK);
      } else if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 3) {
        Paint_DrawString_EN(50, 40, "Sec", &Font24, WHITE, BLACK);
        Paint_DrawString_EN(60, 170, "-", &Font24, WHITE, BLACK);
        Paint_DrawString_EN(180, 170, "+", &Font24, WHITE, BLACK);
      } else if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 4) {
        Paint_DrawString_EN(50, 40, "Light", &Font24, WHITE, BLACK);
        Paint_DrawString_EN(60, 170, "-", &Font24, WHITE, BLACK);
        Paint_DrawString_EN(180, 170, "+", &Font24, WHITE, BLACK);
      }

      if (mypoint.x_point < 120 && mypoint.y_point < 120 && Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro !=0)  //左上  模式修改
      {
        Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro = Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro + 1;
        if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro > 4) {
          Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro = 0;
        }

      }
      else if (mypoint.x_point > 121 && mypoint.y_point > 160)  // 增加  0, 160, 120, 240
      {
        if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 1) 
        {
          Hour++;
          if (Hour > 23) 
          {
            Hour = 0;
          }
        } 
        else if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 2) 
        {
          Min++;
          if (Min > 59) 
          {
            Min = 0;
          }
        } 
        else if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 3) 
        {
          Sec++;
          if (Sec > 59) 
          {
            Sec = 0;
          }
        }
        else if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 4) 
        {
          iLight=iLight+1;
          if (iLight > 100) 
          {
            iLight = 100;
          }
          DEV_SET_PWM(iLight);
        }
      
      } 
      else if (mypoint.x_point < 120 && mypoint.y_point > 160)  // 减少  121, 160, 240, 240
      {
        if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 1) {
          Hour--;
          if (Hour < 0) {
            Hour = 23;
          }
        } else if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 2) {
          Min--;
          if (Min < 0) {
            Min = 59;
          }
        } else if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 3) {
          Sec--;
          if (Sec < 0) {
            Sec = 59;
          }
        }else if (Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro == 4) 
        {
          iLight=iLight-1;
          if (iLight < 0) 
          {
            iLight = 0;
          }
          DEV_SET_PWM(iLight);
        }



      }

  }
  else if(gesture == CST816S_Gesture_Left)
  {

    if(Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro==5)
    {
      Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro=0;
    }
    else
    {
      Mode_0Over_1Hou_2Min_3Sec_4Light_5gyro=5;
    }
  }
  else if(gesture == CST816S_Gesture_Right)
  {
      iPicSeq++;
      if(iPicSeq>7)
      {
        iPicSeq = 0;
      }
  }
  else if(gesture == CST816S_Gesture_Up)
  {
    //iLight=100;
    iLight = iLight_restore;
    if(iLight<=0)
    {
      iLight =0;
    }  
    else if(iLight>=100)
    {
      iLight = 100;
    }
    DEV_SET_PWM(iLight);
  }
  else if(gesture == CST816S_Gesture_Down) // 向下只是关闭,
  {
    //iLight=100;
    iLight_restore = iLight;
    iLight = 0;
    DEV_SET_PWM(iLight);
  }

  


}


功能设定注释掉了陀螺仪,往左划:显示/关闭时间,往右划:切换下一张图片。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
时间依然可以显示,为了能看清,文字的背景都是黑色
在这里插入图片描述
三、展望
到这里,还存在一些不足,比如网络授时的问题。我之前买了一个 microUSB 转typeC 的线,想把RP2040连接上ESP8266,但是EPS8266无法通过这条线来供电。。。那就得用俩电池。。。所以现在考虑用到 RP2040-Touch-LCD-1.28 的排线接口到时候 用杜邦线连接上ESP8266。

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

胸毛男

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值