鱼C论坛

 找回密码
 立即注册
查看: 7229|回复: 106

[其他分类] ESP8266:OLED_显示图片

  [复制链接]
回帖奖励 12 鱼币 回复本帖可获得 2 鱼币奖励! 每人限 1 次
发表于 2021-10-6 22:06:59 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 划句顾 于 2022-5-2 17:23 编辑

嘿嘿,明天要去学校了,最后滴放纵

图片取模工具

话不多说,贴出照片:
1.jpg


                               
登录/注册后可看大图




  1. /*
  2. * author:LaoGu
  3. * time:2021/10/6
  4. * purpose:让OLED 屏幕  显示个图片
  5. */
  6. #include<Arduino.h>
  7. #include<U8g2lib.h>

  8. #ifdef U8X8_HAVE_HW_SPI
  9. #include<SPI.h>
  10. #endif
  11. #ifdef U8X8_HAVE_HW_I2C
  12. #include<Wire.h>
  13. #endif

  14. U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,SCL,SDA,U8X8_PIN_NONE);  //对应 OLED 的驱动协议、像素大小以及接线方式

  15. //图片取模
  16. // width: 66, height: 55
  17. const unsigned char col[]U8X8_PROGMEM = {
  18.   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x03,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x03,0xff,0xff,
  19.   0xff,0xff,0xff,0xff,0xef,0xff,0x03,0xff,0xff,0xff,0x8f,0xff,0xff,0x03,0xff,0x03,0xff,0xff,0x3f,0x00,
  20.   0x80,0xff,0x00,0xfe,0x03,0xff,0xff,0x03,0x00,0x00,0x7c,0x78,0xfc,0x03,0xff,0xff,0xc0,0xff,0x1f,0x38,
  21.   0x7e,0xfc,0x03,0xff,0x3f,0xf8,0xff,0xff,0x01,0xff,0xf8,0x03,0xff,0x1f,0xff,0xff,0xff,0x07,0xff,0xfc,
  22.   0x03,0xff,0x87,0xff,0xff,0xff,0x0f,0xff,0xf8,0x03,0xff,0x03,0xfe,0xff,0xff,0x3f,0xfe,0xf8,0x03,0xff,
  23.   0xc1,0xfc,0xff,0xff,0x7f,0xf8,0xfc,0x03,0xff,0xc0,0xfd,0xff,0xff,0xff,0x70,0xf8,0x03,0xff,0x80,0xfd,
  24.   0xff,0xff,0xff,0x71,0xf0,0x03,0x7f,0x80,0xfd,0x7f,0xe0,0xff,0xe3,0xe0,0x03,0x7f,0x80,0xfd,0x3f,0xe4,
  25.   0xff,0xc7,0xe3,0x03,0x3f,0xc0,0xfd,0x1f,0xc8,0xff,0x8f,0xc7,0x03,0x3f,0xc0,0xfd,0x0f,0xd8,0xff,0x0f,
  26.   0xcf,0x03,0x1f,0xc0,0xfc,0x07,0x98,0xff,0x1f,0x8f,0x03,0x1f,0xe0,0xfc,0x03,0x98,0xff,0x3f,0xce,0x03,
  27.   0x0f,0xe0,0xfe,0x03,0x98,0xff,0x7f,0xc0,0x03,0x8d,0x01,0xfe,0x01,0x98,0xff,0x7f,0xe0,0x03,0xce,0x1f,
  28.   0xff,0x01,0x9c,0xff,0xff,0xf8,0x03,0xc6,0xff,0xff,0x01,0xdc,0xff,0xff,0xf8,0x03,0xc7,0xff,0xff,0x01,
  29.   0xde,0xff,0xff,0xf1,0x03,0xe7,0xff,0xff,0x1f,0xcc,0xff,0xff,0xe3,0x03,0xe7,0xff,0xff,0xff,0xe1,0xff,
  30.   0xff,0xe3,0x03,0xe7,0xff,0xff,0xff,0xff,0xff,0xff,0xc7,0x03,0xe7,0xff,0xff,0xff,0xee,0xff,0xff,0xcf,
  31.   0x02,0xe7,0xff,0xff,0x7f,0x77,0xff,0xff,0x8f,0x02,0xe7,0x07,0xff,0xff,0xbf,0xfb,0xff,0x1f,0x02,0x07,
  32.   0x20,0xfe,0xff,0xff,0xfb,0xff,0x1f,0x02,0x87,0x79,0xfe,0xff,0xcf,0xff,0xff,0x3f,0x02,0x87,0x79,0xfc,
  33.   0xff,0xcf,0xff,0xff,0x3f,0x02,0x07,0xf9,0xe0,0xff,0x9f,0xff,0xff,0x3f,0x02,0x3f,0xf8,0x01,0xff,0xcf,
  34.   0xff,0xff,0x7f,0x02,0xff,0xf0,0x39,0xe0,0xe0,0xff,0xff,0x7f,0x02,0xff,0xf1,0xfb,0x03,0xf8,0xff,0xff,
  35.   0xff,0x02,0xff,0xfb,0xf3,0xff,0xff,0xff,0xff,0xff,0x02,0xff,0xf3,0xc7,0xff,0xff,0xff,0xff,0xff,0x02,
  36.   0xff,0xf7,0x1f,0xfe,0xff,0xff,0xff,0xff,0x03,0xff,0xe7,0x7f,0xc0,0xff,0xff,0xff,0xff,0x03,0xff,0xef,
  37.   0xff,0x07,0xff,0xff,0x7f,0xf8,0x03,0xff,0xcf,0xff,0x0f,0xff,0xff,0x1f,0xe0,0x03,0xff,0x9f,0xff,0xcf,
  38.   0xff,0xff,0xff,0xc7,0x03,0xff,0x1f,0xff,0xcf,0xff,0xff,0xff,0x8f,0x03,0xff,0x3f,0xff,0xcf,0xff,0xff,
  39.   0xff,0x9f,0x03,0xff,0x7f,0xfe,0xcf,0xff,0xff,0xff,0x3f,0x03,0xff,0xff,0xf8,0xcf,0xff,0xff,0xff,0x3f,
  40.   0x03,0xff,0xff,0xf1,0xe7,0xff,0xff,0xff,0x7f,0x03,0xff,0xff,0x87,0xe7,0xff,0xff,0x3f,0x7f,0x02,0xff,
  41.   0xff,0x1f,0xe4,0xff,0xff,0x7f,0x7f,0x02,0xff,0xff,0xff,0xe0,0xff,0xff,0x7f,0xfe,0x02,0xff,0xff,0xff,
  42.   0xe7,0xff,0xff,0x7f,0xfe,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0x00 };
  43.   
  44. void setup(){
  45.   u8g2.begin();  
  46.   }

  47. void loop(){
  48.    u8g2.firstPage();
  49.    do{
  50.    u8g2.clearBuffer();
  51.    u8g2.drawXBMP(0,0,66,55,col);  //col就是bitmap
  52.    u8g2.sendBuffer();
  53.    }while(u8g2.nextPage());
  54.     delay(2500);
  55.   }
复制代码



                               
登录/注册后可看大图

知识点:
  u8g2.drawXBM()/drawXBMP() —— 绘制图像
* 绘制图像
* @param x 左上角坐标x
* @param y 左上角坐标y
* @param w 图形宽度
* @param h 图形高度
* @param bitmap 图形内容
举个栗子
         u8g2.drawXBM(x ,y  ,w , h , bitmap)
   或者u8g2.drawXBMP(x ,y  ,w , h , bitmap)




                               
登录/注册后可看大图

再在oled里面加个进度条


图片如下:
2.jpg

代码:
  1. /*
  2. * author:LaoGu
  3. * time:2021/10/6
  4. * purpose:让OLED 屏幕  加载个图片和进度条
  5. */
  6. #include<Arduino.h>
  7. #include<U8g2lib.h>

  8. #ifdef U8X8_HAVE_HW_SPI
  9. #include<SPI.h>
  10. #endif
  11. #ifdef U8X8_HAVE_HW_I2C
  12. #include<Wire.h>
  13. #endif

  14. U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,SCL,SDA,U8X8_PIN_NONE);  //对应 OLED 的驱动协议、像素大小以及接线方式

  15. int H =72;

  16. //图片取模
  17. // width: 66, height: 55
  18. const unsigned char col[] U8X8_PROGMEM = {
  19.   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x03,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x03,0xff,0xff,
  20.   0xff,0xff,0xff,0xff,0xef,0xff,0x03,0xff,0xff,0xff,0x8f,0xff,0xff,0x03,0xff,0x03,0xff,0xff,0x3f,0x00,
  21.   0x80,0xff,0x00,0xfe,0x03,0xff,0xff,0x03,0x00,0x00,0x7c,0x78,0xfc,0x03,0xff,0xff,0xc0,0xff,0x1f,0x38,
  22.   0x7e,0xfc,0x03,0xff,0x3f,0xf8,0xff,0xff,0x01,0xff,0xf8,0x03,0xff,0x1f,0xff,0xff,0xff,0x07,0xff,0xfc,
  23.   0x03,0xff,0x87,0xff,0xff,0xff,0x0f,0xff,0xf8,0x03,0xff,0x03,0xfe,0xff,0xff,0x3f,0xfe,0xf8,0x03,0xff,
  24.   0xc1,0xfc,0xff,0xff,0x7f,0xf8,0xfc,0x03,0xff,0xc0,0xfd,0xff,0xff,0xff,0x70,0xf8,0x03,0xff,0x80,0xfd,
  25.   0xff,0xff,0xff,0x71,0xf0,0x03,0x7f,0x80,0xfd,0x7f,0xe0,0xff,0xe3,0xe0,0x03,0x7f,0x80,0xfd,0x3f,0xe4,
  26.   0xff,0xc7,0xe3,0x03,0x3f,0xc0,0xfd,0x1f,0xc8,0xff,0x8f,0xc7,0x03,0x3f,0xc0,0xfd,0x0f,0xd8,0xff,0x0f,
  27.   0xcf,0x03,0x1f,0xc0,0xfc,0x07,0x98,0xff,0x1f,0x8f,0x03,0x1f,0xe0,0xfc,0x03,0x98,0xff,0x3f,0xce,0x03,
  28.   0x0f,0xe0,0xfe,0x03,0x98,0xff,0x7f,0xc0,0x03,0x8d,0x01,0xfe,0x01,0x98,0xff,0x7f,0xe0,0x03,0xce,0x1f,
  29.   0xff,0x01,0x9c,0xff,0xff,0xf8,0x03,0xc6,0xff,0xff,0x01,0xdc,0xff,0xff,0xf8,0x03,0xc7,0xff,0xff,0x01,
  30.   0xde,0xff,0xff,0xf1,0x03,0xe7,0xff,0xff,0x1f,0xcc,0xff,0xff,0xe3,0x03,0xe7,0xff,0xff,0xff,0xe1,0xff,
  31.   0xff,0xe3,0x03,0xe7,0xff,0xff,0xff,0xff,0xff,0xff,0xc7,0x03,0xe7,0xff,0xff,0xff,0xee,0xff,0xff,0xcf,
  32.   0x02,0xe7,0xff,0xff,0x7f,0x77,0xff,0xff,0x8f,0x02,0xe7,0x07,0xff,0xff,0xbf,0xfb,0xff,0x1f,0x02,0x07,
  33.   0x20,0xfe,0xff,0xff,0xfb,0xff,0x1f,0x02,0x87,0x79,0xfe,0xff,0xcf,0xff,0xff,0x3f,0x02,0x87,0x79,0xfc,
  34.   0xff,0xcf,0xff,0xff,0x3f,0x02,0x07,0xf9,0xe0,0xff,0x9f,0xff,0xff,0x3f,0x02,0x3f,0xf8,0x01,0xff,0xcf,
  35.   0xff,0xff,0x7f,0x02,0xff,0xf0,0x39,0xe0,0xe0,0xff,0xff,0x7f,0x02,0xff,0xf1,0xfb,0x03,0xf8,0xff,0xff,
  36.   0xff,0x02,0xff,0xfb,0xf3,0xff,0xff,0xff,0xff,0xff,0x02,0xff,0xf3,0xc7,0xff,0xff,0xff,0xff,0xff,0x02,
  37.   0xff,0xf7,0x1f,0xfe,0xff,0xff,0xff,0xff,0x03,0xff,0xe7,0x7f,0xc0,0xff,0xff,0xff,0xff,0x03,0xff,0xef,
  38.   0xff,0x07,0xff,0xff,0x7f,0xf8,0x03,0xff,0xcf,0xff,0x0f,0xff,0xff,0x1f,0xe0,0x03,0xff,0x9f,0xff,0xcf,
  39.   0xff,0xff,0xff,0xc7,0x03,0xff,0x1f,0xff,0xcf,0xff,0xff,0xff,0x8f,0x03,0xff,0x3f,0xff,0xcf,0xff,0xff,
  40.   0xff,0x9f,0x03,0xff,0x7f,0xfe,0xcf,0xff,0xff,0xff,0x3f,0x03,0xff,0xff,0xf8,0xcf,0xff,0xff,0xff,0x3f,
  41.   0x03,0xff,0xff,0xf1,0xe7,0xff,0xff,0xff,0x7f,0x03,0xff,0xff,0x87,0xe7,0xff,0xff,0x3f,0x7f,0x02,0xff,
  42.   0xff,0x1f,0xe4,0xff,0xff,0x7f,0x7f,0x02,0xff,0xff,0xff,0xe0,0xff,0xff,0x7f,0xfe,0x02,0xff,0xff,0xff,
  43.   0xe7,0xff,0xff,0x7f,0xfe,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0x00 };
  44.   
  45. void setup(){
  46.   u8g2.begin();  
  47.   }

  48. void loop(){
  49.    u8g2.setFont(u8g2_font_unifont_t_chinese2); //设置字体
  50.    
  51.    u8g2.firstPage();
  52.    do{
  53.    u8g2.clearBuffer();
  54.    u8g2.drawStr(70,20,"Loading");
  55.    u8g2.drawXBMP(0,0,66,55,col);
  56.    u8g2.sendBuffer();
  57.    //画一个空心方形
  58.        u8g2.drawFrame(70,30,41,6);  
  59.       
  60.       //下面两条line组成进度条
  61.        u8g2.drawLine(72,32,H,32);   //进度条1
  62.        u8g2.drawLine(72,33,H,33);   //进度条2
  63.      
  64.      //这个让进度条动起来
  65.        if(H<105)
  66.           H += 5;
  67.        else
  68.           H = 72;
  69.    }while(u8g2.nextPage());
  70.     delay(2500);
  71.   }
复制代码



                               
登录/注册后可看大图

点赞球球了
关注.png
三连.png
演示视频在这里

评分

参与人数 2荣誉 +6 鱼币 +1 收起 理由
一点沙 + 5 鱼C有你更精彩^_^
鸬鹚鸟 + 1 + 1 鱼C有你更精彩^_^

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-10-7 21:48:42 | 显示全部楼层
本帖最后由 划句顾 于 2021-10-7 22:06 编辑

回复可以百分百拿到币

可不可以顺便去B站帮我的视频点赞呐

https://www.bilibili.com/video/B ... id_from=333.999.0.0

三连(粉色-文字透明-关注在下面-弹-手抖).gif
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-10-8 20:05:04 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-9 10:56:14 | 显示全部楼层

回帖奖励 +2 鱼币

感谢分享!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-10-9 11:11:14 | 显示全部楼层

回帖奖励 +2 鱼币

厉害
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-9 11:12:08 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-9 11:20:07 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-9 15:37:14 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-9 16:35:41 | 显示全部楼层

回帖奖励 +2 鱼币

水鱼币
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-10-9 21:05:40 | 显示全部楼层

回帖奖励 +2 鱼币

牛掰
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-10 11:12:51 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-10 12:54:37 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-10 13:20:21 | 显示全部楼层

回帖奖励 +2 鱼币

三连了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-10-10 20:58:25 | 显示全部楼层

回帖奖励 +2 鱼币

厉害
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-10 21:05:51 | 显示全部楼层

回帖奖励 +2 鱼币

谢谢你的鱼币
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-10-10 21:16:24 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-11 08:55:19 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-11 11:10:41 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-12 21:31:36 | 显示全部楼层

回帖奖励 +2 鱼币

666
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-13 11:54:29 | 显示全部楼层

回帖奖励 +2 鱼币

cy
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-19 13:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表