oled制作动画效果图

oled

一 制作oled下载库文件

https://u16460183.ctfile.com/fs/16460183-296052483
文件夹说明:

Adafruit_SSD1306-master —— OLED库

Adafruit-GFX-Library-master —— 图形库

LS_DrawForOLED —— 主程序


image.png

在arduino文件中加载两种库文件,上传之后如果报错的话需要进行修改文件内容,找到arduino libraries文件进行修改代码
出现错误!


错误信息

error("Height incorrect, please fix Adafruit_SSD1306.h!");

错误信息意思是指:

高度不正确,请修正Adafruit_SSD1306.h!

(1)进入Arduino安装文件夹的libraries文件夹的Adfruit_SSD1306-master 找到Adafruit_SSD1306.h


image.png

打开此文件,找到第70行左右


image.png

默认是定义 SSD1306_128_32 ,由于我们使用的是128*64的OLED,所以,把原来的#define SSD1306_128_32,前面加上//

把#define SSD_128_64 前面的//去掉

二 。 制作一张BMP图片

image.png

首先要有一张BMP图片


image.png

自己用windows自带的画版画了一张大气的 晴朗大山浮云图,保存为BMP格式。

通过软件找到图片的点阵像素,经过像素出现像素码。


image.png

代码编写

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4

Adafruit_SSD1306 display(OLED_RESET);

static const unsigned char PROGMEM logo[] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0x83,0xC0,0x00,0x00,0x00,0x02,0x00,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x07,0x00,0xFC,0x40,0x00,0x00,0x00,0x03,0x00,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x0C,0x07,0x10,0x20,0x00,0x00,0x00,0x01,0xC0,0x00,0x01,0x80,0x00,0x00,
0x00,0x00,0x08,0x7C,0xC0,0x30,0x00,0x00,0x00,0x00,0xC0,0x00,0x03,0x80,0x00,0x00,
0x00,0x00,0x09,0xC0,0x60,0x10,0x00,0x00,0x00,0x00,0x00,0x78,0x07,0x00,0x00,0x00,
0x00,0x7C,0x07,0x00,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0xFE,0x0E,0x00,0x00,0x00,
0x00,0xC7,0x9C,0x00,0x30,0x10,0x00,0x00,0x00,0x00,0x03,0xFF,0x00,0x00,0x00,0x00,
0x01,0x80,0x70,0x00,0x10,0x10,0x00,0x00,0x00,0x00,0x07,0xFF,0x80,0x00,0x00,0x00,
0x01,0x80,0x00,0x00,0x30,0x10,0x00,0x00,0x00,0x00,0x0F,0xFF,0xC0,0x00,0x00,0x00,
0x00,0x80,0x00,0x00,0x60,0x1C,0x00,0x00,0x00,0x00,0x0F,0xFF,0xE0,0x00,0x00,0x00,
0x00,0x80,0x00,0x01,0xC0,0x04,0x00,0x00,0x00,0x00,0x1F,0xFF,0xE2,0x00,0x00,0x00,
0x00,0x80,0x00,0x07,0xFF,0xF8,0x00,0x00,0x00,0x00,0x1F,0xFF,0xE1,0xF0,0x00,0x00,
0x00,0xC0,0x00,0x3E,0x00,0x00,0x00,0x00,0x00,0x1F,0xC7,0xFF,0xE1,0xF0,0x00,0x00,
0x00,0x7F,0xFF,0xE0,0x0C,0x00,0x00,0x00,0x00,0x0F,0xC7,0xFF,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x61,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x80,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0x00,0x38,0x00,0x00,0x3E,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x00,0x23,0x00,0x04,0x00,0x07,0x00,0x00,0x00,
0x00,0x00,0x00,0x18,0x00,0x04,0x00,0x00,0x41,0x00,0x0C,0x06,0x07,0x80,0x00,0x00,
0x00,0x00,0x00,0x30,0x00,0x02,0x00,0x00,0xC0,0x80,0x1C,0x07,0x01,0xC0,0x00,0x00,
0x00,0x00,0x00,0x60,0x00,0x03,0x00,0x01,0x80,0x60,0x78,0x07,0x00,0x60,0x00,0x00,
0x00,0x00,0x00,0xCF,0x80,0x01,0x00,0x03,0x00,0x30,0x00,0x07,0x00,0x00,0x00,0x00,
0x00,0x00,0x03,0xF8,0x7F,0xFF,0x80,0x06,0x00,0x18,0x00,0x07,0x00,0x00,0x00,0x00,
0x00,0x00,0x07,0x80,0x00,0x00,0x40,0x0C,0x00,0x0C,0x00,0x06,0x00,0x00,0x00,0x00,
0x00,0x00,0x1F,0xFF,0xFF,0xFF,0x20,0x18,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x70,0x00,0x00,0x00,0x30,0x30,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xC0,0x00,0x00,0x00,0x18,0x43,0xFE,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFE,0x40,0x03,0xFF,0x60,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,
0x00,0x06,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,
0x00,0x0F,0xFF,0xE0,0x00,0x00,0x00,0xC1,0xFF,0xFF,0xC6,0x00,0x00,0x00,0x00,0x00,
0x00,0x1A,0x00,0x1F,0xFF,0xFF,0xC0,0x60,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,
0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x30,0x3F,0xFF,0xE0,0xC0,0x00,0x00,0x00,0x00,
0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,
0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x0F,0xFE,0x18,0x00,0x00,0x00,0x00,
0x03,0x3F,0xFF,0xFF,0xFF,0xFF,0x80,0x06,0x7F,0xF8,0x00,0x06,0x00,0x00,0x00,0x00,
0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,
0x0C,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0x80,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,
0x18,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x80,0x00,0x0F,0xFF,0x30,0x00,0x00,0x00,
0x10,0x00,0x00,0x00,0x00,0x3F,0xFC,0x00,0xC1,0xFF,0xF0,0x00,0x08,0x00,0x00,0x00,
0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x07,0x00,0x00,0x00,
0x10,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x00,0x7F,0xFE,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
}

void loop() {
display.drawBitmap(0, 0, logo, 128, 64, 1); //在坐标X0,Y0的位置开始显示图片
//128是取模软件显示的宽度
//64是取模软件显示的高度
display.display(); //把缓存的都显示
delay(1);

display.clearDisplay(); //清除屏幕
}

三。动态六边形

image.png

代码

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4

Adafruit_SSD1306 display(OLED_RESET);

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

int nFrames = 36;

void setup() {
Serial.begin(9600);

display.begin(SSD1306_SWITCHCAPVCC,0x3C);

display.display();
delay(1000);

display.clearDisplay();
}

void loop() {
for (int frame=0; frame < nFrames; frame++)
{
HariChord(frame);
}

for (int frame=(nFrames-1); frame >= 0; frame--)
{
HariChord(frame);
}
}

void HariChord(int frame)
{
display.clearDisplay();
int n = 7;
int r = frame * 64 / nFrames;
float rot = frame * 2PI / nFrames;
for (int i=0; i<(n-1); i++)
{
float a = rot + i * 2
PI / n;
int x1 = 64 + cos(a) * r;
int y1 = 32 + sin(a) * r;
for (int j=i+1; j<n; j++)
{
a = rot + j * 2*PI / n;
int x2 = 64 + cos(a) * r;
int y2 = 32 + sin(a) * r;
display.drawLine(x1,y1, x2,y2, WHITE);
}
}
display.display();
}

推荐阅读更多精彩内容