分享

用arduino和OLED制作火柴人奔跑动画

 漫步之心情 2021-10-25

用arduino和OLED制作火柴人奔跑动画

文章图片1

2.为动画创建位图

文章图片2

这可能是最耗时的步骤。你必须创建一组框架,这将适合128x32格式。您可以尝试从任何拖鞋剪贴片中创建它们,您可以在网上找到。

所有的框架需要是黑白的!!!

我创造了显示奔跑生物的帧,一共八张

3.连接

文章图片3

OLED

arduino

GND

GND

VCC

VCC

SDA

A4

SCK

A5

OLED 显示屏有四个引脚,分别是:
1.SDA(数据线) SCK(时钟线) VDD(3.3V) GND
2.在UNO开发板上I2C接口,SDA对应D4,SCK对应D5
3.在MEGA2560开发板上I2C接口,SDA对应D20, SCL对应D21

4.创建位图的代码表示

文章图片4
文章图片5

①使用在线取模软件

文章图片6

要创建位图的代码表示,我们将使用在线工具

你可以找到它去下面的网址

https://javl./image2cpp/

②执行以下步骤:

  • Select Image(选择图像)部分,逐个打开帧文件
  • 通过检查图像设置部分检查上传的Image Settings(图像)是否正确
  • 如果想要具有黑色背景,并且只点亮线像素,请检查倒置图像颜色,在Background选择Black
文章图片7
  • Output(输出部分)在Code output format(代码输出格式)中指定'Arduino code ,single bitmap'在Identifier/Prefix(标识符/前缀)中提供动画名称,必须要英文按Generate code(生成按钮)保存生成的代码。它将被粘贴到arduino编译器

4.创建动画代码

①首先,我们需要引用所需的头文件

#include <Wire.h>#include <Adafruit_GFX.h>#include <Adafruit_SSD1306.h>

前一个用于 I2C 接口,其他两个用于与 OLED 显示器配合工作

②我们需要定义显示屏的大小

#define SCREEN_WIDTH 128 // OLED 显示宽度128 in pixels#define SCREEN_HEIGHT 64 // OLED 显示高度64 in pixels

③引用函数库,里面有宣布通过 OLED 显示连接的引脚。有了这些别针,我们宣布显示器本身

#define OLED_RESET 4Adafruit_SSD1306 display(OLED_RESET);

然后,您必须复制粘贴我们从Image2cpp 中获得的代码

这是一个相当长的代码,所以我不会粘贴在这里的全部。我只显示一帧

static const unsigned char Frame1 [] PROGMEM = {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, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x83, 0x80, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x03, 0x0c, 0x40, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xe1, 0x0c, 0x60, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x1f, 0xff, 0x80, 0x20, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x01, 0xf9, 0xe0, 0x20, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0xcc, 0x78, 0x60, 0x00, 0x00, 0x03, 0xe7, 0x80, 0x00, 0x00, 0x64, 0x1f, 0xc0, 0x00, 0x00, 0x0e, 0xff, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x0e, 0x00, 0x00, 0x00, 0x33, 0xf0, 0x00, 0x00, 0x00, 0x30, 0xf8, 0x00, 0x00, 0x00, 0x18, 0x1f, 0xf0, 0x00, 0x00, 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x86, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 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};

然后,在设置功能中,我们正在初始化 OLED 显示屏

void setup() {Serial.begin(9600);delay(500);// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)}

然后,我们有循环功能,我们重播所有10帧在50ms间隔

void loop() {// Diplay Animation// Frame1display.clearDisplay();display.drawBitmap(30,0,RUN1, 80, 32, 1);display.display();delay(50);// Frame2display.clearDisplay();display.drawBitmap(30,0,RUN2, 80, 32, 1);display.display();delay(50);// Frame3display.clearDisplay();display.drawBitmap(30,0,RUN3, 80, 32, 1);display.display();delay(50);// Frame4display.clearDisplay();display.drawBitmap(30,0,RUN4, 80, 32, 1);display.display();delay(50);// Frame5display.clearDisplay();display.drawBitmap(30,0,RUN5, 80, 32, 1);display.display();delay(50);// Frame6display.clearDisplay();display.drawBitmap(30,0,RUN6, 80, 32, 1);display.display();delay(50);// Frame7display.clearDisplay();display.drawBitmap(30,0,RUN7, 80, 32, 1);display.display();delay(50);// Frame8display.clearDisplay();display.drawBitmap(30,0,RUN8, 80, 32, 1);display.display();delay(50);// Frame9display.clearDisplay();display.drawBitmap(30,0,RUN9, 80, 32, 1);display.display();delay(50); // Frame10display.clearDisplay();display.drawBitmap(30,0,RUN10, 80, 32, 1);display.display();delay(50); 
文章图片8

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多