Arduino的Oled模块使用
1. 字模显示原理及取模软件的使用
我们使用的OLED屏是由方形的发光点阵列组成的,分辨率为128x64。英文和数字最小可用8x8像素,汉字最小显示像素为16x16,通常为了显示效果,英文和数字通常使用8x16像素表示。要显示需要的字符只需对应点亮像素区域中对应的发光点即可。
字模一般都是通过取模软件生成的,接下来介绍「PCtoLCD」取模软件的使用:
1. Windows系统下双击启动软件,点击「模式」,选择「字符模式」,通常默认就是字符模式。
2. 点击「选项」进行字模配置。通常字模配置要根据程序驱动方式来选择,本篇中我们选择阴码、逐行式、顺向,其他选项如下图所示。
3. 输入汉字。点击生成字模或者保存字模,就会得到对应的点阵数据。
杨(0) 永(1) 生(2)
{0x10,0x00,0x11,0xF8,0x10,0x10,0x10,0x20,0xFC,0x40,0x10,0x80,0x31,0xFE,0x38,0x92},
{0x54,0x92,0x54,0x92,0x91,0x12,0x11,0x22,0x12,0x22,0x14,0x42,0x10,0x94,0x11,0x08},/*"杨",0*/
/* (16 X 16 , 宋体 )*/
{0x02,0x00,0x01,0x00,0x00,0x80,0x1F,0x00,0x01,0x04,0x01,0x08,0x7D,0x90,0x05,0xA0},
{0x05,0x40,0x09,0x40,0x09,0x20,0x11,0x10,0x21,0x08,0xC1,0x06,0x05,0x00,0x02,0x00},/*"永",1*/
/* (16 X 16 , 宋体 )*/
{0x01,0x00,0x11,0x00,0x11,0x00,0x11,0x00,0x3F,0xFC,0x21,0x00,0x41,0x00,0x81,0x00},
{0x01,0x00,0x3F,0xF8,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00},/*"生",2*/
/* (16 X 16 , 宋体 )*/
2. 实验材料
- Uno R3开发板
- 配套USB数据线
- 面包板及配套连接线
- OLED显示屏
3. 实验步骤
1. 根据原理图搭建电路图。
IIC接口只需要两根线。OLED屏的VCC和GND分别连接开发板的3.3V和GND,OLED屏的SDA和SCL分别连接开发板A4和A5。
实验原理图如下图所示:
2. 新建sketch,拷贝如下代码替换自动生成的代码并进行保存。
需要两个库
库名 | Adafruit_GFX | Adafruit_SSD1306 |
搜索到名字 | Adafruit-GFX-Library | Adafruit_SSD1306 |
作者 | adafruit | adafruit |
github地址 | https://github.com/adafruit/Adafruit-GFX-Library | https://github.com/adafruit/Adafruit_SSD1306 |
/*
OLED显示汉字
*/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
//取16X16汉字字模 逐行式 顺向高位在前
static const unsigned char PROGMEM str1[] =
{
0x10,0x00,0x11,0xF8,0x10,0x10,0x10,0x20,0xFC,0x40,0x10,0x80,0x31,0xFE,0x38,0x92,
0x54,0x92,0x54,0x92,0x91,0x12,0x11,0x22,0x12,0x22,0x14,0x42,0x10,0x94,0x11,0x08
};/*"杨",0*/
static const unsigned char PROGMEM str2[] =
{
0x02,0x00,0x01,0x00,0x00,0x80,0x1F,0x00,0x01,0x04,0x01,0x08,0x7D,0x90,0x05,0xA0,
0x05,0x40,0x09,0x40,0x09,0x20,0x11,0x10,0x21,0x08,0xC1,0x06,0x05,0x00,0x02,0x00
};/*"永",1*/
static const unsigned char PROGMEM str3[] =
{
0x01,0x00,0x11,0x00,0x11,0x00,0x11,0x00,0x3F,0xFC,0x21,0x00,0x41,0x00,0x81,0x00,
0x01,0x00,0x3F,0xF8,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00
};/*"生",2*/
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextColor(WHITE);//开像素点发光
display.clearDisplay();//清屏
display.setTextSize(1); //设置字体大小
display.setCursor(35, 5);//设置显示位置
display.println("-TonyCode-");//输出字符
display.drawBitmap(32, 32, str1, 16, 16, 1); //画出字符对应点阵数据
display.drawBitmap(48, 32, str2, 16, 16, 1); //画出字符对应点阵数据
display.drawBitmap(64, 32, str3, 16, 16, 1); //画出字符对应点阵数据
display.display();//开显示
}
void loop() {
}
https://blog.csdn.net/TonyIOT/article/details/96762017
用python转c++格式
import re
text = """
杨(0) 永(1) 生(2)
{0x10,0x00,0x11,0xF8,0x10,0x10,0x10,0x20,0xFC,0x40,0x10,0x80,0x31,0xFE,0x38,0x92},
{0x54,0x92,0x54,0x92,0x91,0x12,0x11,0x22,0x12,0x22,0x14,0x42,0x10,0x94,0x11,0x08},/*"杨",0*/
/* (16 X 16 , 宋体 )*/
{0x02,0x00,0x01,0x00,0x00,0x80,0x1F,0x00,0x01,0x04,0x01,0x08,0x7D,0x90,0x05,0xA0},
{0x05,0x40,0x09,0x40,0x09,0x20,0x11,0x10,0x21,0x08,0xC1,0x06,0x05,0x00,0x02,0x00},/*"永",1*/
/* (16 X 16 , 宋体 )*/
{0x01,0x00,0x11,0x00,0x11,0x00,0x11,0x00,0x3F,0xFC,0x21,0x00,0x41,0x00,0x81,0x00},
{0x01,0x00,0x3F,0xF8,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00},/*"生",2*/
/* (16 X 16 , 宋体 )*/
"""
r_list = re.compile('{(.*?)}.*?{(.*?)},/\\*("\\w",\\d+)', re.S).findall(text)
# print(r_list)
for i in r_list:
half_one = i[0]
half_two = i[1]
zhu = i[2]
# print(half_one, half_two, zhu)
final_text = """
static const unsigned char PROGMEM str%s[] =
{
%s,
%s
};/*%s*/""" % (r_list.index(i)+1, half_one, half_two, zhu)
print(final_text)
1.需要U8g2lib库
2.电路图
图fritzing模块来自GitHub库
GPIO overview
GPIO | Function | State | Restrictions |
---|---|---|---|
0 | Boot mode select | 3.3V | No Hi-Z |
1 | TX0 | - | Not usable during Serial transmission |
2 | Boot mode select TX1 |
3.3V (boot only) | Don’t connect to ground at boot time Sends debug data at boot time |
3 | RX0 | - | Not usable during Serial transmission |
4 | SDA (I²C) | - | 对应D1引脚 |
5 | SCL (I²C) | - | 对应D2引脚 |
6 - 11 | Flash connection | x | Not usable, and not broken out |
12 | MISO (SPI) | - | - |
13 | MOSI (SPI) | - | - |
14 | SCK (SPI) | - | - |
15 | SS (SPI) | 0V | Pull-up resistor not usable |
16 | Wake up from sleep | - | No pull-up resistor, but pull-down instead Should be connected to RST to wake up |
3.1,显示英文
#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, /* clock=*/ D2, /* data=*/ D1, /* reset=*/ U8X8_PIN_NONE); // 此处 D1 D2是对应焊接的脚针
void setup(void) {
u8g2.begin();
}
void loop(void) {
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
u8g2.drawStr(0,10,"Hello World!"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
delay(1000);
}
3.2.显示汉字
#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, /* clock=*/ D2, /* data=*/ D1, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display
void setup(void) {
u8g2.begin();
u8g2.enableUTF8Print(); // enable UTF8 support for the Arduino print() function
}
void loop(void) {
u8g2.setFont(u8g2_font_unifont_t_chinese2); // use chinese2 for all the glyphs of "你好世界"
u8g2.setFontDirection(0);
u8g2.clearBuffer();
u8g2.setCursor(0, 15);
u8g2.print("kali论坛");
u8g2.setCursor(0, 30);
u8g2.print("bbskali.cn"); // Chinese "Hello World"
u8g2.setCursor(0, 45);
u8g2.print("kali黑客教学");
u8g2.sendBuffer();
delay(1000);
}
显示多行文字
#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_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ D2, /* data=*/ D1, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display
#define FONT u8g2_font_wqy14_t_gb2312b
//#define FONT u8g2_font_wqy16_t_chinese1
//#define FONT u8g2_font_wqy16_t_gb2312b
// The next two macros define the scroll speed of the short story
#define SCROLL_DELTA 2
#define SCROLL_DELAY 200
const char c_str[] =
"Shen Nong\n\n"
"KALI论坛介绍\n"
"kali论坛创建于20\n"
"17年,站长Priess\n"
"本论坛基于kali安\n"
"全研究和网络安全\n"
"为方便小伙伴学习\n"
"我们搭建了此论坛\n"
"论坛学习完全免费\n"
"我们的网址:\n"
"bbskali,cn\n"
"微信公众号:\n"
"【kali黑客教学】\n"
"感谢大家关注。\n";
char buf[48]; // there are at most 8 chinese glyphs per line, max buf size is 8*3 = 24
uint8_t total_lines; // the total number of lines in the story
uint8_t i; // loop variable for the lines
uint8_t line_cnt; // number of lines to draw, usually equal to lines_per_draw
uint8_t start_line; // topmost visible line, derived from top_window_pos
uint8_t lines_per_draw; // how many lines to draw on the screen, derived from font and display height
uint16_t glyph_height; // height of the glyphs
uint16_t top_window_pos; // defines the display position in pixel within the text
uint16_t total_height; // total height in pixel, derived from font height and total_lines
u8g2_uint_t top_offset; // offset between the first visible line and the display
void setup(void) {
/* U8g2 Project: SSD1306 Test Board */
pinMode(D2, OUTPUT);
pinMode(D1, OUTPUT);
digitalWrite(10, 0);
digitalWrite(9, 0);
/* U8g2 Project: T6963 Test Board */
//pinMode(18, OUTPUT);
//digitalWrite(18, 1);
/* U8g2 Project: KS0108 Test Board */
//pinMode(16, OUTPUT);
//digitalWrite(16, 0);
/* U8g2 Project: LC7981 Test Board, connect RW to GND */
//pinMode(17, OUTPUT);
//digitalWrite(17, 0);
/* U8g2 Project: Pax Instruments Shield: Enable Backlight */
//pinMode(6, OUTPUT);
//digitalWrite(6, 0);
u8g2.begin();
/* select a font */
// u8g2.setFont(u8g2_font_wqy12_t_chinese1); // two unknown glyphs
//u8g2.setFont(u8g2_font_wqy12_t_chinese3); // two unknown glyphs
//u8g2.setFont(u8g2_font_wqy12_t_gb2312a); // ";" is missing
//u8g2.setFont(u8g2_font_wqy12_t_gb2312b); // all glyphs available
u8g2.setFont(FONT);
/* calculate the length of the text in lines */
total_lines = u8x8_GetStringLineCnt(c_str);
/* get the height of the glyphs */
glyph_height = u8g2.getMaxCharHeight();
/* calculate the height of the text in pixel */
total_height = (uint16_t)total_lines * (uint16_t)glyph_height;
/* calculate how many lines must be drawn on the screen */
lines_per_draw = u8g2.getDisplayHeight() / glyph_height;
lines_per_draw += 2;
/* start at the top of the text */
top_window_pos = 0;
}
void loop(void) {
start_line = top_window_pos / glyph_height;
top_offset = top_window_pos % glyph_height;
line_cnt = total_lines - start_line;
if ( line_cnt > lines_per_draw )
line_cnt = lines_per_draw;
u8g2.firstPage();
do {
for( i = 0; i < line_cnt; i++ )
{
/* copy a line of the text to the local buffer */
u8x8_CopyStringLine(buf, i+start_line, c_str);
/* draw the content of the local buffer */
u8g2.drawUTF8(0, i*glyph_height-top_offset +glyph_height, buf);
}
} while ( u8g2.nextPage() );
delay(SCROLL_DELAY);
top_window_pos += SCROLL_DELTA;
}
1.3TFT ST7789 IPS SPI display.
接线
TFT_DC 8
TFT_RST 9
TFT_SDA 11
TFT_SCL 13
GND
VCC 5V/3.3V 都行
BLK不用接
文件下载https://cloud.189.cn/t/aqYNZrFVFNni
/***************************************************
1.3TFT ST7789 IPS SPI display.
接线
TFT_DC 8
TFT_RST 9
TFT_SDA 11
TFT_SCL 13
GND
VCC 5V/3.3V 都行
BLK不用接
****************************************************/
#include <Adafruit_GFX.h> // Core graphics library by Adafruit
#include <Arduino_ST7789.h> // Hardware-specific library for ST7789 (with or without CS pin)
#include <SPI.h>
#include <SimpleDHT.h>
#define TFT_DC 8
#define TFT_RST 9
//#define TFT_CS 10 // only for displays with CS pin
#define TFT_MOSI 11 // for hardware SPI data pin (all of available pins)
#define TFT_SCLK 13 // for hardware SPI sclk pin (all of available pins)
#define DebugSerial Serial
//You can use different type of hardware initialization
//using hardware SPI (11, 13 on UNO; 51, 52 on MEGA; ICSP-4, ICSP-3 on DUE and etc)
//Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST); //for display without CS pin
//Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST, TFT_CS); //for display with CS pin
//or you can use software SPI on all available pins (slow)
Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK); //for display without CS pin
//Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_CS); //for display with CS pin
int pinDHT11 = 4;
SimpleDHT11 dht11(pinDHT11);
float p = 3.1415926;
byte temp2 = 0;
byte humi2 = 0;
byte flag = 0;
//室
const unsigned char PROGMEM str1[] =
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x80,0x00,
0x00,0x01,0x80,0x00,0x00,0x00,0x80,0x00,0x04,0x00,0x80,0x10,0x07,0xFF,0xFF,0xF8,
0x0C,0x00,0x00,0x30,0x0C,0x00,0x00,0x60,0x1C,0x00,0x01,0x40,0x03,0xFF,0xFF,0x80,
0x00,0x07,0x00,0x00,0x00,0x0C,0x08,0x00,0x00,0x18,0x06,0x00,0x00,0x30,0x03,0x00,
0x00,0x40,0x01,0x80,0x01,0xFF,0xFF,0xC0,0x01,0xFE,0x00,0xC0,0x00,0x81,0x00,0x80,
0x00,0x01,0xC0,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x81,0x80,0x03,0xFF,0xFF,0xC0,
0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,
0x00,0x01,0x80,0x18,0x3F,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
//内
const unsigned char PROGMEM str2[] =
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0xC0,0x00,
0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,
0x04,0x01,0x80,0x40,0x07,0xFF,0xFF,0xF0,0x06,0x01,0x80,0x60,0x06,0x01,0x80,0x60,
0x06,0x01,0x00,0x60,0x06,0x03,0x00,0x60,0x06,0x03,0x00,0x60,0x06,0x03,0xC0,0x60,
0x06,0x06,0x60,0x60,0x06,0x06,0x38,0x60,0x06,0x0C,0x1C,0x60,0x06,0x18,0x0E,0x60,
0x06,0x10,0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x80,0x02,0x60,0x07,0x00,0x00,0x60,
0x06,0x00,0x00,0x60,0x06,0x00,0x00,0x60,0x06,0x00,0x00,0x60,0x06,0x00,0x18,0xC0,
0x06,0x00,0x07,0xC0,0x06,0x00,0x01,0xC0,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
//温
const unsigned char PROGMEM str3[] =
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x08,0x00,0x80,
0x06,0x0F,0xFF,0xC0,0x03,0x0C,0x00,0x80,0x03,0x0C,0x00,0x80,0x00,0x2C,0x00,0x80,
0x00,0x4C,0x00,0x80,0x00,0x4F,0xFF,0x80,0x00,0x4C,0x00,0x80,0x30,0x4C,0x00,0x80,
0x18,0x8C,0x00,0x80,0x0C,0x8C,0x00,0x80,0x08,0x8F,0xFF,0x80,0x01,0x0C,0x00,0x80,
0x01,0x08,0x00,0x00,0x01,0x00,0x00,0x00,0x03,0x20,0x00,0x20,0x02,0x3F,0xFF,0xF0,
0x02,0x31,0x8C,0x60,0x06,0x31,0x8C,0x60,0x3E,0x31,0x8C,0x60,0x0E,0x31,0x8C,0x60,
0x0C,0x31,0x8C,0x60,0x0C,0x31,0x8C,0x60,0x0C,0x31,0x8C,0x60,0x0C,0x31,0x8C,0x60,
0x0C,0x31,0x8C,0x6C,0x0D,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
//度
const unsigned char PROGMEM str4[] =
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0xC0,0x00,
0x00,0x00,0xE0,0x10,0x04,0x00,0x40,0x38,0x07,0xFF,0xFF,0xFC,0x06,0x04,0x04,0x00,
0x06,0x07,0x07,0x00,0x06,0x06,0x06,0x00,0x06,0x06,0x06,0x30,0x07,0xFF,0xFF,0xF8,
0x06,0x06,0x06,0x00,0x06,0x06,0x06,0x00,0x06,0x06,0x06,0x00,0x06,0x06,0x06,0x00,
0x06,0x07,0xFE,0x00,0x06,0x06,0x06,0x00,0x04,0x00,0x01,0x00,0x04,0x3F,0xFF,0x80,
0x0C,0x04,0x03,0x80,0x0C,0x02,0x07,0x00,0x0C,0x03,0x06,0x00,0x08,0x01,0x0C,0x00,
0x08,0x00,0xD8,0x00,0x18,0x00,0x70,0x00,0x10,0x00,0xF8,0x00,0x10,0x03,0x9E,0x00,
0x20,0x0E,0x07,0xF8,0x20,0x70,0x00,0xF8,0x47,0x80,0x00,0x10,0x00,0x00,0x00,0x00,};
//湿
const unsigned char PROGMEM str5[] ={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x00,0x00,
0x06,0x0F,0xFF,0xE0,0x07,0x0C,0x00,0x60,0x03,0x0C,0x00,0x60,0x03,0x0C,0x00,0x60,
0x00,0x2C,0x00,0x60,0x00,0x4F,0xFF,0xE0,0x60,0x4C,0x00,0x60,0x30,0x4C,0x00,0x60,
0x1C,0x8C,0x00,0x60,0x0C,0x8C,0x00,0x60,0x0C,0x8F,0xFF,0xE0,0x01,0x0C,0x84,0x60,
0x01,0x08,0xC6,0x00,0x03,0x00,0xC6,0x00,0x02,0x00,0xC6,0x18,0x06,0x20,0xC6,0x1C,
0x06,0x10,0xC6,0x30,0x7C,0x18,0xC6,0x60,0x0C,0x0C,0xC6,0x40,0x0C,0x0C,0xC6,0x80,
0x0C,0x0C,0xC7,0x00,0x0C,0x04,0xC6,0x00,0x1C,0x00,0xC6,0x00,0x1C,0x00,0xC6,0x00,
0x1C,0x00,0xC6,0x08,0x0C,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
//永
const unsigned char PROGMEM str6[]=
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x03,0x80,0x00,
0x00,0x01,0xC0,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x80,0x00,0x00,0xFF,0xE0,0x40,0x00,0x00,0xC0,0x60,0x00,0x00,0xC0,0xE0,
0x00,0x00,0xC0,0xC0,0x00,0x10,0xA1,0x80,0x1F,0xF8,0xA3,0x00,0x00,0x30,0xA6,0x00,
0x00,0x30,0x9C,0x00,0x00,0x60,0x98,0x00,0x00,0x60,0x88,0x00,0x00,0xC0,0x8C,0x00,
0x00,0xC0,0x8C,0x00,0x01,0x80,0x86,0x00,0x01,0x00,0x83,0x00,0x03,0x00,0x83,0x80,
0x06,0x00,0x81,0xC0,0x0C,0x00,0x80,0xF0,0x08,0x00,0x80,0x7C,0x10,0x31,0x80,0x30,
0x20,0x0F,0x80,0x10,0x00,0x03,0x80,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,};
//生
const unsigned char PROGMEM str7[]=
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0xC0,0x00,
0x00,0x81,0x80,0x00,0x00,0xE1,0x80,0x00,0x01,0xC1,0x80,0x00,0x01,0x81,0x80,0x00,
0x01,0x81,0x80,0x00,0x03,0x01,0x80,0x60,0x03,0xFF,0xFF,0xF0,0x02,0x01,0x80,0x00,
0x06,0x01,0x80,0x00,0x04,0x01,0x80,0x00,0x08,0x01,0x80,0x00,0x08,0x01,0x80,0x00,
0x10,0x01,0x80,0x80,0x20,0x01,0x81,0xC0,0x03,0xFF,0xFF,0xC0,0x00,0x01,0x80,0x00,
0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,
0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x00,0x00,0x01,0x80,0x18,
0x3F,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
const unsigned char PROGMEM str8[]={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,0x1F,0xF0,0x00,
0x00,0xFF,0xFF,0x00,0x03,0xFF,0xFF,0xC0,0x0F,0xC0,0x03,0xF0,0x1F,0x00,0x00,0xF8,
0x7C,0x00,0x00,0x3C,0xF0,0x00,0x00,0x0E,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*"︵",0*/
void setup(void) {
Serial.begin(9600);
Serial.print("Hello! ST7789 TFT Test");
tft.init(240, 240); // initialize a ST7789 chip, 240x240 pixels
Serial.println("Initialized");
// tft.initR(INITR_144GREENTAB);
tft.setRotation(2); //彩屏显示数据位置
tft.setTextWrap(false);
tft.fillScreen(BLACK); //背景颜色设置
}
void loop() {
tft.setCursor(0, 0); //位置(x, y)
tft.setTextSize(4); // 字体大小
tft.setTextColor(YELLOW); // 字体颜色
tft.print("by"); //画出字符对应点阵数据
tft.drawBitmap(64, 0, str6, 32,32, BLUE); //画出字符对应点阵数据
tft.drawBitmap(96, 0, str7, 32,32, BLUE); //画出字符对应点阵数据
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT11 failed, err=");
Serial.println(err);
delay(1000);
return;
}
Serial.print("Sample OK: ");
Serial.print((int)temperature); Serial.print(" ℃, ");
Serial.print((int)humidity); Serial.println(" %");
tft.drawBitmap(0, 80, str1, 32,32, 0x7FF); //画出字符对应点阵数据
tft.drawBitmap(32, 80, str2, 32,32, 0x7FF); //画出字符对应点阵数据
tft.drawBitmap(64, 80, str3, 32,32, 0x7FF); //画出字符对应点阵数据
tft.drawBitmap(96, 80, str4, 32,32, 0x7FF); //画出字符对应点阵数据
tft.setCursor(128, 80); //位置(x, y)
tft.setTextSize(4); // 字体大小
tft.setTextColor(0x7FF); // 字体颜色
tft.print(":"); //画出字符对应点阵数据
tft.print(temperature); //画出字符对应点阵数据
if (temp2 != temperature){
tft.setCursor(128, 80); //位置(x, y)
tft.setTextSize(4); // 字体大小
tft.setTextColor(BLACK);
tft.print(":");
tft.print(temp2); //画出字符对应点阵数据
temp2 = temperature;
}
tft.drawBitmap(0, 120, str1, 32,32, 0xFFFF ); //画出字符对应点阵数据
tft.drawBitmap(32, 120, str2, 32,32, 0xFFFF); //画出字符对应点阵数据
tft.drawBitmap(64, 120, str5, 32,32, 0xFFFF); //画出字符对应点阵数据
tft.drawBitmap(96, 120, str4, 32,32, 0xFFFF); //画出字符对应点阵数据
tft.setCursor(128, 120); //位置(x, y)
tft.setTextSize(4); // 字体大小
tft.setTextColor(0xFFFF); // 字体颜色
tft.print(":"); //画出字符对应点阵数据
tft.print(humidity); //画出字符对应点阵数据
if (humi2 != humidity){
tft.setCursor(128, 120); //位置(x, y)
tft.setTextSize(4); // 字体大小
tft.setTextColor(BLACK);
tft.print(":");
tft.print(humi2); //画出字符对应点阵数据
humi2 = humidity;
}
if (temperature <= 25 && 18<=temperature && 40 <= humidity && humidity <= 70)
{
tft.setCursor(0, 170); //位置(x, y)
tft.setTextSize(4); // 字体大小
tft.setTextColor(RED); // 字体颜色
tft.print("(^_^)");
Serial.println("开心");
// // 黑色
// tft.setCursor(0, 170); //位置(x, y)
// tft.setTextSize(4); // 字体大小
// tft.setTextColor(BLACK); // 字体颜色
// tft.print("(^");
// tft.drawBitmap(56, 170, str8, 32,32, BLACK);
// tft.setCursor(96, 170); //位置(x, y)
// tft.setTextSize(4); // 字体大小
// tft.setTextColor(BLACK); // 字体颜色
// tft.print("^)");
}
else{
Serial.println("难过");
tft.setCursor(0, 170); //位置(x, y)
tft.setTextSize(4); // 字体大小
tft.setTextColor(RED); // 字体颜色
tft.print("(^");
tft.drawBitmap(56, 170, str8, 32,32, RED);
tft.setCursor(96, 170); //位置(x, y)
tft.setTextSize(4); // 字体大小
tft.setTextColor(RED); // 字体颜色
tft.print("^)");
// // 黑色
// tft.setCursor(0, 170); //位置(x, y)
// tft.setTextSize(4); // 字体大小
// tft.setTextColor(BLACK); // 字体颜色
// tft.print("(^_^)");
}
}
本文作者: 永生
本文链接: https://yys.zone/detail/?id=193
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
评论列表 (0 条评论)