马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 划句顾 于 2022-5-2 17:23 编辑
嘿嘿,明天要去学校了,最后滴放纵
图片取模工具
话不多说,贴出照片:
/*
* 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里面加个进度条
图片如下:
代码:/*
* 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);
}
点赞球球了
演示视频在这里 |