鱼C论坛

 找回密码
 立即注册
查看: 9218|回复: 113

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

  [复制链接]
发表于 2021-10-6 22:06:59 | 显示全部楼层 |阅读模式

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

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

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

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

图片取模工具

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


                               
登录/注册后可看大图


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

#ifdef U8X8_HAVE_HW_SPI
#include<SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include<Wire.h>
#endif

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

//图片取模
// width: 66, height: 55
const unsigned char col[]U8X8_PROGMEM = { 
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x03,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x03,0xff,0xff,
  0xff,0xff,0xff,0xff,0xef,0xff,0x03,0xff,0xff,0xff,0x8f,0xff,0xff,0x03,0xff,0x03,0xff,0xff,0x3f,0x00,
  0x80,0xff,0x00,0xfe,0x03,0xff,0xff,0x03,0x00,0x00,0x7c,0x78,0xfc,0x03,0xff,0xff,0xc0,0xff,0x1f,0x38,
  0x7e,0xfc,0x03,0xff,0x3f,0xf8,0xff,0xff,0x01,0xff,0xf8,0x03,0xff,0x1f,0xff,0xff,0xff,0x07,0xff,0xfc,
  0x03,0xff,0x87,0xff,0xff,0xff,0x0f,0xff,0xf8,0x03,0xff,0x03,0xfe,0xff,0xff,0x3f,0xfe,0xf8,0x03,0xff,
  0xc1,0xfc,0xff,0xff,0x7f,0xf8,0xfc,0x03,0xff,0xc0,0xfd,0xff,0xff,0xff,0x70,0xf8,0x03,0xff,0x80,0xfd,
  0xff,0xff,0xff,0x71,0xf0,0x03,0x7f,0x80,0xfd,0x7f,0xe0,0xff,0xe3,0xe0,0x03,0x7f,0x80,0xfd,0x3f,0xe4,
  0xff,0xc7,0xe3,0x03,0x3f,0xc0,0xfd,0x1f,0xc8,0xff,0x8f,0xc7,0x03,0x3f,0xc0,0xfd,0x0f,0xd8,0xff,0x0f,
  0xcf,0x03,0x1f,0xc0,0xfc,0x07,0x98,0xff,0x1f,0x8f,0x03,0x1f,0xe0,0xfc,0x03,0x98,0xff,0x3f,0xce,0x03,
  0x0f,0xe0,0xfe,0x03,0x98,0xff,0x7f,0xc0,0x03,0x8d,0x01,0xfe,0x01,0x98,0xff,0x7f,0xe0,0x03,0xce,0x1f,
  0xff,0x01,0x9c,0xff,0xff,0xf8,0x03,0xc6,0xff,0xff,0x01,0xdc,0xff,0xff,0xf8,0x03,0xc7,0xff,0xff,0x01,
  0xde,0xff,0xff,0xf1,0x03,0xe7,0xff,0xff,0x1f,0xcc,0xff,0xff,0xe3,0x03,0xe7,0xff,0xff,0xff,0xe1,0xff,
  0xff,0xe3,0x03,0xe7,0xff,0xff,0xff,0xff,0xff,0xff,0xc7,0x03,0xe7,0xff,0xff,0xff,0xee,0xff,0xff,0xcf,
  0x02,0xe7,0xff,0xff,0x7f,0x77,0xff,0xff,0x8f,0x02,0xe7,0x07,0xff,0xff,0xbf,0xfb,0xff,0x1f,0x02,0x07,
  0x20,0xfe,0xff,0xff,0xfb,0xff,0x1f,0x02,0x87,0x79,0xfe,0xff,0xcf,0xff,0xff,0x3f,0x02,0x87,0x79,0xfc,
  0xff,0xcf,0xff,0xff,0x3f,0x02,0x07,0xf9,0xe0,0xff,0x9f,0xff,0xff,0x3f,0x02,0x3f,0xf8,0x01,0xff,0xcf,
  0xff,0xff,0x7f,0x02,0xff,0xf0,0x39,0xe0,0xe0,0xff,0xff,0x7f,0x02,0xff,0xf1,0xfb,0x03,0xf8,0xff,0xff,
  0xff,0x02,0xff,0xfb,0xf3,0xff,0xff,0xff,0xff,0xff,0x02,0xff,0xf3,0xc7,0xff,0xff,0xff,0xff,0xff,0x02,
  0xff,0xf7,0x1f,0xfe,0xff,0xff,0xff,0xff,0x03,0xff,0xe7,0x7f,0xc0,0xff,0xff,0xff,0xff,0x03,0xff,0xef,
  0xff,0x07,0xff,0xff,0x7f,0xf8,0x03,0xff,0xcf,0xff,0x0f,0xff,0xff,0x1f,0xe0,0x03,0xff,0x9f,0xff,0xcf,
  0xff,0xff,0xff,0xc7,0x03,0xff,0x1f,0xff,0xcf,0xff,0xff,0xff,0x8f,0x03,0xff,0x3f,0xff,0xcf,0xff,0xff,
  0xff,0x9f,0x03,0xff,0x7f,0xfe,0xcf,0xff,0xff,0xff,0x3f,0x03,0xff,0xff,0xf8,0xcf,0xff,0xff,0xff,0x3f,
  0x03,0xff,0xff,0xf1,0xe7,0xff,0xff,0xff,0x7f,0x03,0xff,0xff,0x87,0xe7,0xff,0xff,0x3f,0x7f,0x02,0xff,
  0xff,0x1f,0xe4,0xff,0xff,0x7f,0x7f,0x02,0xff,0xff,0xff,0xe0,0xff,0xff,0x7f,0xfe,0x02,0xff,0xff,0xff,
  0xe7,0xff,0xff,0x7f,0xfe,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0x00 };
  
void setup(){
  u8g2.begin();  
  }

void loop(){
   u8g2.firstPage();
   do{
   u8g2.clearBuffer();
   u8g2.drawXBMP(0,0,66,55,col);  //col就是bitmap
   u8g2.sendBuffer();
   }while(u8g2.nextPage());
    delay(2500);
  }


                               
登录/注册后可看大图

知识点:
  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

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

#ifdef U8X8_HAVE_HW_SPI
#include<SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include<Wire.h>
#endif

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

int H =72;

//图片取模
// width: 66, height: 55
const unsigned char col[] U8X8_PROGMEM = { 
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x03,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x03,0xff,0xff,
  0xff,0xff,0xff,0xff,0xef,0xff,0x03,0xff,0xff,0xff,0x8f,0xff,0xff,0x03,0xff,0x03,0xff,0xff,0x3f,0x00,
  0x80,0xff,0x00,0xfe,0x03,0xff,0xff,0x03,0x00,0x00,0x7c,0x78,0xfc,0x03,0xff,0xff,0xc0,0xff,0x1f,0x38,
  0x7e,0xfc,0x03,0xff,0x3f,0xf8,0xff,0xff,0x01,0xff,0xf8,0x03,0xff,0x1f,0xff,0xff,0xff,0x07,0xff,0xfc,
  0x03,0xff,0x87,0xff,0xff,0xff,0x0f,0xff,0xf8,0x03,0xff,0x03,0xfe,0xff,0xff,0x3f,0xfe,0xf8,0x03,0xff,
  0xc1,0xfc,0xff,0xff,0x7f,0xf8,0xfc,0x03,0xff,0xc0,0xfd,0xff,0xff,0xff,0x70,0xf8,0x03,0xff,0x80,0xfd,
  0xff,0xff,0xff,0x71,0xf0,0x03,0x7f,0x80,0xfd,0x7f,0xe0,0xff,0xe3,0xe0,0x03,0x7f,0x80,0xfd,0x3f,0xe4,
  0xff,0xc7,0xe3,0x03,0x3f,0xc0,0xfd,0x1f,0xc8,0xff,0x8f,0xc7,0x03,0x3f,0xc0,0xfd,0x0f,0xd8,0xff,0x0f,
  0xcf,0x03,0x1f,0xc0,0xfc,0x07,0x98,0xff,0x1f,0x8f,0x03,0x1f,0xe0,0xfc,0x03,0x98,0xff,0x3f,0xce,0x03,
  0x0f,0xe0,0xfe,0x03,0x98,0xff,0x7f,0xc0,0x03,0x8d,0x01,0xfe,0x01,0x98,0xff,0x7f,0xe0,0x03,0xce,0x1f,
  0xff,0x01,0x9c,0xff,0xff,0xf8,0x03,0xc6,0xff,0xff,0x01,0xdc,0xff,0xff,0xf8,0x03,0xc7,0xff,0xff,0x01,
  0xde,0xff,0xff,0xf1,0x03,0xe7,0xff,0xff,0x1f,0xcc,0xff,0xff,0xe3,0x03,0xe7,0xff,0xff,0xff,0xe1,0xff,
  0xff,0xe3,0x03,0xe7,0xff,0xff,0xff,0xff,0xff,0xff,0xc7,0x03,0xe7,0xff,0xff,0xff,0xee,0xff,0xff,0xcf,
  0x02,0xe7,0xff,0xff,0x7f,0x77,0xff,0xff,0x8f,0x02,0xe7,0x07,0xff,0xff,0xbf,0xfb,0xff,0x1f,0x02,0x07,
  0x20,0xfe,0xff,0xff,0xfb,0xff,0x1f,0x02,0x87,0x79,0xfe,0xff,0xcf,0xff,0xff,0x3f,0x02,0x87,0x79,0xfc,
  0xff,0xcf,0xff,0xff,0x3f,0x02,0x07,0xf9,0xe0,0xff,0x9f,0xff,0xff,0x3f,0x02,0x3f,0xf8,0x01,0xff,0xcf,
  0xff,0xff,0x7f,0x02,0xff,0xf0,0x39,0xe0,0xe0,0xff,0xff,0x7f,0x02,0xff,0xf1,0xfb,0x03,0xf8,0xff,0xff,
  0xff,0x02,0xff,0xfb,0xf3,0xff,0xff,0xff,0xff,0xff,0x02,0xff,0xf3,0xc7,0xff,0xff,0xff,0xff,0xff,0x02,
  0xff,0xf7,0x1f,0xfe,0xff,0xff,0xff,0xff,0x03,0xff,0xe7,0x7f,0xc0,0xff,0xff,0xff,0xff,0x03,0xff,0xef,
  0xff,0x07,0xff,0xff,0x7f,0xf8,0x03,0xff,0xcf,0xff,0x0f,0xff,0xff,0x1f,0xe0,0x03,0xff,0x9f,0xff,0xcf,
  0xff,0xff,0xff,0xc7,0x03,0xff,0x1f,0xff,0xcf,0xff,0xff,0xff,0x8f,0x03,0xff,0x3f,0xff,0xcf,0xff,0xff,
  0xff,0x9f,0x03,0xff,0x7f,0xfe,0xcf,0xff,0xff,0xff,0x3f,0x03,0xff,0xff,0xf8,0xcf,0xff,0xff,0xff,0x3f,
  0x03,0xff,0xff,0xf1,0xe7,0xff,0xff,0xff,0x7f,0x03,0xff,0xff,0x87,0xe7,0xff,0xff,0x3f,0x7f,0x02,0xff,
  0xff,0x1f,0xe4,0xff,0xff,0x7f,0x7f,0x02,0xff,0xff,0xff,0xe0,0xff,0xff,0x7f,0xfe,0x02,0xff,0xff,0xff,
  0xe7,0xff,0xff,0x7f,0xfe,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0x00 };
  
void setup(){
  u8g2.begin();  
  }

void loop(){
   u8g2.setFont(u8g2_font_unifont_t_chinese2); //设置字体
   
   u8g2.firstPage();
   do{
   u8g2.clearBuffer();
   u8g2.drawStr(70,20,"Loading");
   u8g2.drawXBMP(0,0,66,55,col);
   u8g2.sendBuffer();
   //画一个空心方形
       u8g2.drawFrame(70,30,41,6);  
      
      //下面两条line组成进度条
       u8g2.drawLine(72,32,H,32);   //进度条1
       u8g2.drawLine(72,33,H,33);   //进度条2
     
     //这个让进度条动起来
       if(H<105)
          H += 5;
       else
          H = 72;
   }while(u8g2.nextPage());
    delay(2500);
  }


                               
登录/注册后可看大图

点赞球球了
关注.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-12-31 01:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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