You are on page 1of 21

RST 引脚重置显示。它是主动低引脚的意思;你可以把显示器拉低来复位。您还可

以将这个 pin 连接到 Arduino 复位,这样它将自动复位屏幕。

CE(Chip Enable)引脚用于从共享相同 SPI 总线的多个连接设备中选择一个。它


也是一个主动低引脚。

D/C(Data/Command)引脚告诉显示它接收的数据是命令还是可显示的数据。

DIN 是 SPI 接口的串行数据引脚。

CLK 是 SPI 接口的串行时钟引脚。

VCC 引脚为 LCD 提供电源,我们将其连接到 Arduino 上的 3.3V 电压引脚。

BL(背光)引脚控制显示的背光。为了控制它的亮度,你可以添加一个电位器或连
接这个引脚到任何 pwm 能力的 Arduino 引脚。

GND 应与 Arduino 地面连接

连接诺基亚 5110 液晶显示模块到 Arduino Uno


在我们上载代码和向显示发送数据之前,让我们将显示与 Arduino 挂钩。
连接相当简单。当我们实现软件 SPI 时,我们有灵活的 pin 选项。您可以将数据传输引脚连接
到任何数字 I/O 引脚。在我们的示例中,串行时钟(CLK)、串行数据(DIN)、数据/命令(DC)、芯片
启用(CE)和复位(RST)引脚从引脚 7 一直连接到 Arduino 上的引脚 3。
但不幸的是,液晶显示器有 3v 的通信级别,所以我们不能直接连接这些引脚到 Arduino。我
们需要一些保护。这可以通过改变级别来实现。
转换电平最便宜和最简单的方法之一是在每个数据传输引脚上增加内联电阻。只是加 10
kΩCLK 之间的电阻,DIN,D / C,RST 别针和一个 1 kΩCE 之间的电阻。
最后,背光(提单)销连接到 3.3 v 通过 330Ω 限流电阻。如果你想控制它的亮度,你可以添加一
个电位器或将这个引脚连接到任何 pwm 支持的 Arduino 引脚上。

为 Nokia 5110 LCD 模块安装库


PCD8544 液晶控制器具有灵活而复杂的驱动程序。使用 PCD8544 控制器需要大量的内存寻
址知识。幸运的是,Adafruit 的 PCD8544 Nokia 5110 LCD 库可以隐藏所有的复杂性,这样我
们就可以发出简单的命令来控制显示。
要安装库,请导航到示意图>包括库>管理库……等待库管理器下载库索引并更新已安装库
列 表 。
输入“nokia”过滤搜索。应该有两个条目。寻找 Adafruit PCD8544 诺基亚 5110 液晶库。单击
该条目,然后选择 Install。
这个库是一个特定于硬件的库,用于处理底层函数。它需要搭配 Adafruit GFX 库来显示点、
线、圆、矩形等图形原语。也安装这个库。

Arduino 代码-显示文本
现在有趣的东西来了!
下面的测试草图将打印“Hello World!”显示的信息。它还包括
显示反向文本
显示的数字
以基数显示数字(十六进制,12 月)
显示 ASCII 符号
旋转文本
这将使您全面了解如何使用诺基亚 5110 液晶显示器,并可作为更实际的实验和项目的基础。
试着画出草图,然后我们再仔细分析一下。

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// Declare LCD object for software SPI


// Adafruit_PCD8544(CLK,DIN,D/C,CE,RST);
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

int rotatetext = 1;

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

//Initialize Display
display.begin();
// you can change the contrast around to adapt the display
for the best viewing!
display.setContrast(57);

// Clear the buffer.


display.clearDisplay();

// Display Text
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("Hello world!");
display.display();
delay(2000);
display.clearDisplay();

// Display Inverted Text


display.setTextColor(WHITE, BLACK); // 'inverted' text
display.setCursor(0,0);
display.println("Hello world!");
display.display();
delay(2000);
display.clearDisplay();

// Scaling Font Size


display.setTextColor(BLACK);
display.setCursor(0,0);
display.setTextSize(2);
display.println("Hello!");
display.display();
delay(2000);
display.clearDisplay();

// Display Numbers
display.setTextSize(1);
display.setCursor(0,0);
display.println(123456789);
display.display();
delay(2000);
display.clearDisplay();

// Specifying Base For Numbers


display.setCursor(0,0);
display.print("0x"); display.print(0xFF, HEX);
display.print("(HEX) = ");
display.print(0xFF, DEC);
display.println("(DEC)");
display.display();
delay(2000);
display.clearDisplay();

// Display ASCII Characters


display.setCursor(0,0);
display.setTextSize(2);
display.write(3);
display.display();
delay(2000);
display.clearDisplay();

// Text Rotation
while(1)
{
display.clearDisplay();
display.setRotation(rotatetext); // rotate 90 degrees
counter clockwise, can also use values of 2 and 3 to go further.
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("Text Rotation");
display.display();
delay(1000);
display.clearDisplay();
rotatetext++;
}
}

void loop() {}

n 草图首先包括三个库,即 SPI。h, Adafruit_GFX.h 和 Adafruit_PCD8544.h。接下来,我们需要


创 建 一 个 LCD 对 象 。 此 对 象 接 受 5 个 参 数 并 指 定 哪 些 Arduino 引 脚 连 接 到 LCD 的
CLK 、Din、D/C、CE 和 RST 引脚。我们还定义了 rotatetext 变量,稍后将对此进行解释。有趣的
东西来了!
下面的测试草图将打印“Hello World!”显示的信息。它还包括
显示反向文本
显示的数字
以基数显示数字(十六进制,12 月)
显示 ASCII 符号
旋转文本
这将使您全面了解如何使用诺基亚 5110 液晶显示器,并可作为更实际的实验和项目的基础。
试着画出草图,然后我们再仔细分析一下。

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// Initialize LCD object for software SPI


// Adafruit_PCD8544(CLK,DIN,D/C,CE,RST);
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

int rotatetext = 1;

在 setup 函 数 中 : 我 们 需 要 使 用 begin() 函 数 初 始 化 LCD 对 象 。 我 们 还 需 要 使 用


setContrast(value)函数设置显示的对比度,其值可以在 0-100 之间。然而,50-60 之间的值会
产生很好的结果。
接下来,在将第一条消息打印到屏幕上之前清除缓冲区。

//Initialize Display
display.begin();

// you can change the contrast around to adapt the display for the
best viewing!
display.setContrast(57);

// Clear the buffer.


display.clearDisplay();

36/5000
显示简单文本(Hello World)

display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("Hello world!");
display.display();
delay(2000);
display.clearDisplay()
或者在屏幕上显示文本,我们需要设置字体大小。这可以通过调用
setTextSize()并将字体大小(从 1 开始)作为参数传递来实现。
接下来,我们需要通过调用函数 setTextColor()来设置字体颜色。通过参数黑
色为黑暗的背景和通过白色为明亮的背景。现在,在打印消息之前,我们需要通
过调用函数 setCursor(X,Y)来设置光标的位置。
屏幕上的像素由它们的水平(X)和垂直(Y)坐标表示。坐标系把原点(0,0)放在左
上角,正 X 向右递增,正 Y 向下递增。
我们可以使用简单的 print(" ")或 println(" ")函数在屏幕上打印消息,就像
在串行监视器上打印数据一样。记住,println()将光标移动到新行。
为了使库在屏幕缓冲区上执行非常快的数学操作(每秒超过 100 帧),对打印函
数的调用不会立即将屏幕缓冲区的内容传输到 PCD8544 控制器。需要一个
display()命令来指示库执行从 ATmega328P 中的屏幕缓冲区到 PCD8544 控制器
的内部内存的批量传输。一旦内存被传输,屏幕缓冲区对应的像素将显示在液晶
显示器上。

显示反向文本

// Display Inverted Text


display.setTextColor(WHITE, BLACK);
display.setCursor(0,0);
display.println("Hello world!");
display.display();
delay(2000);
display.clearDisplay();

为了显示反向文本,我们将再次调用
setTextColor(FontColor,BackgroundColor)函数。如果你注意了,你知道我们
之前只传递了一个参数给这个函数,但是现在我们传递了两个参数。这是可能的
因为函数重载。函数重载是一种创建多个同名但具有不同参数集的函数的能力。
对重载函数的调用将根据传递的参数运行该函数的特定实现。
在我们的示例中,传递 setTextColor(黑色、白色)将在填充的背景上呈现黑色
文本。

缩放字体大小

// Scaling Font Size


display.setTextColor(BLACK);
display.setCursor(0,0);
display.setTextSize(2);
display.println("Hello!");
display.display();
delay(2000);
display.clearDisplay();

在本教程的前面,我们调用 setTextSize()函数来设置字体大小,并将 1 作为参


数传递。可以使用此函数通过传递任何非负整数来缩放字体。
字符以 5:7 的比例呈现。意义,通过字体大小 1 将在 5×7 像素渲染文本的每个字
符;通过 2 将在 10×14 像素渲染文本每字符等等。

显示的数字

// Display Numbers
display.setTextSize(1);
display.setCursor(0,0);
display.println(123456789);
display.display();
delay(2000);
display.clearDisplay();

只需调用 print()或 println()函数,就可以在液晶显示屏上显示数字。这些函


数的重载实现接受 32 位无符号整数,因此只能显示 0 到 4,294,967,295 之间的
数字。

指定数字的基数
// Specifying Base For Numbers
display.setCursor(0,0);
display.print("0x"); display.print(0xFF, HEX);
display.print("(HEX) = ");
display.print(0xFF, DEC);
display.println("(DEC)");
display.display();
delay(2000);
display.clearDisplay();

print()和 println()函数具有第二个可选参数,该参数指定要使用的基(格式);
允许的值有 BIN(二进制或以 2 为底)、OCT(八进制或以 8 为底)、DEC(十进制或以
10 为底)、十六进制(十六进制或以 16 为底)。对于浮点数,此参数指定要使用的
小数位数。例如:
打印(78,BIN)显示“1001110”
打印(78,10 月)显示“116”
打印(78,12 月)显示“78”
打印(78,十六进制)显示“4E”
println(1.23456, 0)给出“1”
println(1.23456, 2)给出“1.23”
println(1.23456, 4)给出“1.2346”
显示 ASCII 符号

// Display ASCII Characters


display.setCursor(0,0);
display.setTextSize(2);
display.write(3);
display.display();
delay(2000);
display.clearDisplay();

函数的作用是:当 write()函数向显示器发送二进制数据时,print()和
println()函数将数据作为人类可读的 ASCII 文本发送到显示器。你可以用这个
函数来显示 ASCII 码。在我们的示例中,发送数字 3 将显示心脏符号。

文本的旋转
// Text Rotation
while(1)
{
display.clearDisplay();
display.setRotation(rotatetext);
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println("Text Rotation");
display.display();
delay(1000);
display.clearDisplay();
rotatetext++;
}

您可以通过调用 setRotation()函数来旋转显示的内容。它允许你在竖屏模式下
查看你的显示器,或者把它倒过来。
该函数只接受一个参数,该参数对应于 4 个基本旋转。这个值可以是从 0 开始的
任何非负整数。每次增加该值时,显示器的内容都会逆时针旋转 90 度。例如:
0 -保持屏幕的标准横向方向。
1 -屏幕旋转 90°。
2 -把屏幕倒过来。
3 - 90°旋转屏幕左边。

Arduino 代码-基本绘图
在这个例子中,我们将尝试一些基本的绘图。这个示意图演示了许多绘图函数,
包括矩形、圆形矩形、圆形和三角形。试着画出草图,然后我们再仔细分析一下。
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// Declare LCD object for software SPI


// Adafruit_PCD8544(CLK,DIN,D/C,CE,RST);
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

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

//Initialize Display
display.begin();

// you can change the contrast around to adapt the display


for the best viewing!
display.setContrast(57);

// Clear the buffer.


display.clearDisplay();

// Draw Rectangle
display.drawRect(0, 0, 60, 40, BLACK);
display.display();
delay(2000);
display.clearDisplay();

//Draw Filled Rectangle


display.fillRect(0, 0, 60, 40, BLACK);
display.display();
delay(2000);
display.clearDisplay();

//Draw Round Rectangle


display.drawRoundRect(0, 0, 60, 40, 8, BLACK);
display.display();
delay(2000);
display.clearDisplay();
//Draw Filled Round Rectangle
display.fillRoundRect(0, 0, 60, 40, 8, BLACK);
display.display();
delay(2000);
display.clearDisplay();

//Draw Circle
display.drawCircle(20, 20, 20, BLACK);
display.display();
delay(2000);
display.clearDisplay();

//Draw Filled Circle


display.fillCircle(20, 20, 20, BLACK);
display.display();
delay(2000);
display.clearDisplay();

//Draw Triangle
display.drawTriangle(20, 0, 0, 40, 40, 40, BLACK);
display.display();
delay(2000);
display.clearDisplay();

//Draw Filled Triangle


display.fillTriangle(20, 0, 0, 40, 40, 40, BLACK);
display.display();
delay(2000);
display.clearDisplay();
}

void loop() {}

大多数代码(包括库和初始化显示)与上面的代码示例相同,只是下面的代码片
段用于绘制基本绘图。

画矩形
// Draw Rectangle
display.drawRect(0, 0, 60, 40, BLACK);
display.display();
delay(2000);
display.clearDisplay();

//Draw Filled Rectangle


display.fillRect(0, 0, 60, 40, BLACK);
display.display();
delay(2000);
display.clearDisplay();

可以使用 drawRect()函数在显示器上绘制矩形。该函数有 5 个参数,即 X 坐标 、


Y 坐标、宽度、高度和颜色。实际上,这个函数绘制了一个带 1 像素边框的空心矩
形。可以使用 fillRect()函数绘制填充矩形。

画圆矩形
//Draw Round Rectangle
display.drawRoundRect(0, 0, 60, 40, 8, BLACK);
display.display();
delay(2000);
display.clearDisplay();

//Draw Filled Round Rectangle


display.fillRoundRect(0, 0, 60, 40, 8, BLACK);
display.display();
delay(2000);
display.clearDisplay();

可以使用 drawRoundRect()函数在显示器上绘制圆形矩形。这个函数的参数与
drawRect()函数相同,只是多了一个参数——圆角半径。实际上,这个函数绘制
了一个带 1 像素边框的空心圆形矩形。可以使用 fillRoundRect()函数绘制填充
的圆形矩形。

画圆
//Draw Circle
display.drawCircle(20, 20, 20, BLACK);
display.display();
delay(2000);
display.clearDisplay();

//Draw Filled Circle


display.fillCircle(20, 20, 20, BLACK);
display.display();
delay(2000);
display.clearDisplay()
可以使用 drawCircle()函数在显示器上画圆。该函数有四个参数,即中心的 X
坐标、中心的 Y 坐标、半径和颜色。这个函数绘制一个带 1 像素边框的空心圆。可
以使用 fillCircle()函数绘制填充圆。

画三角形
/Draw Triangle
display.drawTriangle(20, 0, 0, 40, 40, 40, BLACK);
display.display();
delay(2000);
display.clearDisplay();

//Draw Filled Triangle


display.fillTriangle(20, 0, 0, 40, 40, 40, BLACK);
display.display();
delay(2000);
display.clearDisplay();

可以使用 drawTriangle()函数在显示器上绘制三角形。该函数取 7 个参数,即


三角形顶点和颜色的 3 个 xy 坐标(x0, y0, x1, y1, x2, y2)。(X0,y0)表示顶点
(x1,y1)表示左顶点,(x2,y2)表示右顶点。
这个函数绘制带有 1 像素边框的空心三角形。可以使用 fillTriangle()函数绘
制填充三角形。

Arduino 代码-显示位图

最后一个示例显示如何将位图图像绘制到 Nokia 5110 液晶显示器上。这对于创


建公司徽标的闪屏、创建精灵或创建用于显示信息的有趣图形非常有用。复制以
下代码,将其粘贴到 Arduino IDE 中,然后单击 upload。
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// Declare LCD object for software SPI


// Adafruit_PCD8544(CLK,DIN,D/C,CE,RST);
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

// 'Marilyn Monroe 84x48', 84x48px


const unsigned char MarilynMonroe [] PROGMEM = {
0x00, 0x00, 0x00, 0x7f, 0x00, 0x02, 0xfe, 0xf8, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xbe, 0x00,
0x00, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x3f, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x1f, 0xe1, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
0x00, 0x00, 0x0f, 0xf1, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0e, 0xd8, 0xe0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x07, 0xe0,
0x70, 0x00, 0x00, 0x00, 0x00, 0x03,
0x3f, 0xe0, 0x00, 0x07, 0xf0, 0x78, 0x00, 0x00, 0x00, 0x00,
0x01, 0xe0, 0x70, 0x00, 0x0f, 0xee,
0x7c, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x0f,
0xf7, 0x1c, 0x00, 0x00, 0x00, 0x00,
0x07, 0x80, 0x00, 0x0f, 0xc7, 0xf3, 0x1e, 0x00, 0x00, 0x00,
0x00, 0x07, 0xc0, 0x00, 0x0f, 0xf3,
0xdf, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x07, 0xfe, 0x00, 0x08,
0x7d, 0xef, 0xff, 0xc0, 0x00, 0x00,
0x00, 0x7f, 0xff, 0x80, 0x30, 0x0f, 0xfc, 0xe0, 0xc0, 0x00,
0x00, 0x01, 0x9e, 0x73, 0xc0, 0xe0,
0x07, 0xf8, 0xc1, 0xc0, 0x00, 0x00, 0x03, 0xfc, 0x00, 0x01,
0xc0, 0x0f, 0xfd, 0xe1, 0x80, 0x00,
0x00, 0x03, 0xf8, 0x00, 0x01, 0x9c, 0x0f, 0xff, 0xc1, 0xc0,
0x00, 0x00, 0x02, 0xc0, 0x00, 0x01,
0x9f, 0xbf, 0xfe, 0x01, 0x40, 0x00, 0x00, 0x02, 0x60, 0x00,
0x03, 0x07, 0xef, 0xff, 0x01, 0x40,
0x00, 0x00, 0x00, 0x60, 0x00, 0x07, 0x01, 0xf7, 0xff, 0x80,
0xc0, 0x00, 0x00, 0x00, 0x50, 0x01,
0xdf, 0x00, 0x7f, 0xff, 0x1c, 0x80, 0x00, 0x00, 0x00, 0x40,
0x01, 0xff, 0x00, 0x1f, 0xff, 0x1e,
0xe0, 0x00, 0x00, 0x02, 0x08, 0x00, 0x3f, 0x80, 0x07, 0xef,
0x03, 0xe0, 0x00, 0x00, 0x06, 0x08,
0x00, 0x03, 0xc0, 0x07, 0xdf, 0x07, 0xc0, 0x00, 0x00, 0x06,
0x08, 0x0f, 0x81, 0x80, 0x1f, 0xdf,
0x1f, 0x80, 0x00, 0x00, 0x03, 0x08, 0x1f, 0x98, 0x00, 0x3f,
0xfe, 0x19, 0x80, 0x00, 0x00, 0x18,
0x08, 0x3f, 0xfe, 0x00, 0x7f, 0xfe, 0x3f, 0x00, 0x00, 0x00,
0x08, 0x08, 0x30, 0x3f, 0x00, 0xff,
0xff, 0x3f, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x76, 0x0f, 0x89,
0xff, 0xff, 0x9f, 0x00, 0x00, 0x00,
0x03, 0xe0, 0x7f, 0xc3, 0x81, 0xff, 0xfe, 0x9f, 0x80, 0x00,
0x00, 0x03, 0xf0, 0x7f, 0xf3, 0xc3,
0xff, 0xfe, 0x1f, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x7f, 0xfd,
0xc3, 0xff, 0xfe, 0x5e, 0x00, 0x00,
0x00, 0x03, 0xf0, 0x7f, 0xff, 0xc3, 0xff, 0xf3, 0x1e, 0x00,
0x00, 0x00, 0x03, 0xf0, 0x71, 0xff,
0x87, 0xff, 0xe3, 0xff, 0x00, 0x00, 0x00, 0x07, 0xf0, 0x7c,
0x3f, 0x87, 0xff, 0xe3, 0xfe, 0x00,
0x00, 0x00, 0x0f, 0xf0, 0x3c, 0xff, 0x05, 0xff, 0xf3, 0xfc,
0x00, 0x00, 0x00, 0x0f, 0xf0, 0x0f,
0xfe, 0x09, 0xff, 0xf7, 0xfc, 0x00, 0x00, 0x00, 0x08, 0xf8,
0x01, 0xfc, 0x19, 0xff, 0xff, 0xf8,
0x00, 0x00, 0x00, 0x0c, 0x78, 0x00, 0x00, 0x13, 0xff, 0xff,
0xf8, 0x00, 0x00, 0x00, 0x0e, 0x78,
0x00, 0x00, 0x23, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x0e,
0xf8, 0x00, 0x00, 0x47, 0xff, 0xff,
0xf0, 0x00, 0x00, 0x00, 0x0c, 0xfa, 0x00, 0x01, 0x8f, 0xff,
0xff, 0xe0, 0x00, 0x00, 0x00, 0x08,
0x7b, 0x00, 0x03, 0x3f, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00,
0x0c, 0x3b, 0xf8, 0x0f, 0xff, 0xff,
0xff, 0xe0, 0x00, 0x00, 0x00, 0x0f, 0xbb, 0xff, 0xff, 0xff,
0xff, 0xff, 0xf0, 0x00, 0x00, 0x00,
0x07, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x71, 0xff, 0xff, 0xff,
0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x41, 0xff, 0xff,
0xff, 0xff, 0xff, 0xe0, 0x00, 0x00
};

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

//Initialize Display
display.begin();

// you can change the contrast around to adapt the display


for the best viewing!
display.setContrast(57);

// Clear the buffer.


display.clearDisplay();

// Display bitmap
display.drawBitmap(0, 0, MarilynMonroe, 84, 48, BLACK);
display.display();

// Invert Display
//display.invertDisplay(1);
}

void loop() {}
输出是这样的

为了在诺基亚 5110 液晶显示器上显示位图图像,我们需要调用 drawBitmap()函


数。它有 6 个参数,左上角 X 坐标,左上角 Y 坐标,黑白位图字节数组,位图像
素宽度,位图像素高度,颜色。
在我们的示例中,位图图像的大小是 84×48。因此,X 和 Y 坐标设置为 0,而宽度
和高度设置为 84 和 48。

// Display bitmap
display.drawBitmap(0, 0, MarilynMonroe, 84, 48, BLACK);
display.display();

但是,在调用 drawBitmap()函数之前,首先需要绘制一个图像。记住,诺基亚
5110 液晶显示器的屏幕分辨率是 84×48 像素,所以图像比不会正确显示。得到
正确的大小的图像,您可以使用您最喜欢的绘图程序像 Inkscape,Photoshop,油
漆,等等,将画布大小设置为 84×48 像素。
我们把笑玛丽莲·梦露图像为例,转化为 84×48 像素使用油漆和保存为 bmp 格
式。

有了位图之后,就可以将其转换为 PCD8544 控制器能够理解的数组。这可以通过两种方式


实现:在线方法使用 image2cpp,离线方法使用 LCD Assistant。

在线位图阵列生成器- image2cpp
有一个名为 image2cpp 的在线应用程序—http://javl.github。io/image2cpp/可以将你的图像转
换成一个数组。Image2cpp 比 LCD Assistant(后来的解决方案)更新且更强大。它将使你:
转换多个图像同时。
缩放你的图像文件-拉伸/缩放到适合/原始
调整黑白之间的亮度阈值。
重新将图像垂直和/或水平居中。
反向图像颜色
这个工具非常强大,可以离线工作。只需将页面保存到您的 PC 并在浏览器中打开它。感谢
Jasper van Loenen 的杰出贡献。
首先,在浏览器中打开 image2cpp 并选择要在屏幕上显示的任何图像。

图像的尺寸将填充在图像设置下的画布大小选项中。如果你有选中的图片超过 84×48,改成
84×48 和选择适当的缩放选项。您可以在预览部分查看输出。
您可以改变背景颜色或逆变图像颜色,如果需要。
最后,根据您的需要更改最重要的选项—亮度阈值。设置阈值将使像素高于这一水平的白
色和低于黑色。在我们的案例中,我们将其设置为 171,以获取玛丽莲·梦露的详细信息。

这个小预览反映了您在设置中所做的任何更改。您可以在关注它的同时更改设置。
一旦您对结果感到满意,就可以继续生成数据数组。只需选择代码输出格式作为 Arduino 代
码,然后单击 Generate Code 按钮。
仅供您参考,有一个名为 Draw mode 的选项。它实际上是根据显示器的扫描模式来创建图
像的。如果你的图像在你的显示器上看起来乱七八糟,试着改变模式。

就是这样。位图的字节数组将被生成。您可以直接在示例代码中使用输出。一定要给它起个
恰当的名字。然后在 drawBitmap()函数中调用数组。

离线位图阵列发生器- LCD 助手
还有另一个应用程序叫 LCD assistant - http://en.radzio.dxp。pl/bitmap_converter/可以将您的
位图图像转换为数据数组。它没有 image2cpp 那么强大,但仍然受到爱好者的欢迎。
首先,你需要将你的形象转化为 84×48 比特单色位图。您可以使用您最喜欢的绘图程序,如
Inkscape, Photoshop, Paint 等来完成它,就像我们在 MS Paint 中所做的那样。
打开你的文件在油漆和调整女士 84×48。

现在,将文件保存为位图。在保存文件时,选择 Save as type:单色位图(*.bmp;*.dib)。这将生


成 1 位/二进制位图图像,每个像素只有两个可能的值,即 0(黑色)或 1(白色)。

这里唯一的缺点是不能设置亮度阈值级别。默认设置为 50%,不能更改。
无论如何,现在下载 LCD 助手程序。打开可执行文件并从“文件”菜单加载位图。
你用这个工具做不了什么。所以,只要转到文件菜单,点击保存输出选项。将文件保存为文
本文件。
仅供参考,有一个名为字节方向的选项。它实际上是根据显示器的扫描模式来创建图像的。
如果你的图像在你的显示器上看起来乱七八糟,试着改变模式。

就 是这 样。 创建 数组 后, 将其 粘贴 到代 码中 。一 定要 给它 起个 恰当 的名 字。 然后 在
drawBitmap()函数中调用数组。

You might also like