OLED液晶屏幕(4)串口读取文字并分割,液晶屏幕显示

ESP8266-07
0.93存 液晶屏 128*64 驱动芯片 ssd1306
接线
VCC-5v
GND-GND
SCL-D1(SCL)
SDA-D2(SDA)
安装两个库
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

串口输入一句话
液晶屏幕显示出来
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 //4 Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); #define NUMFLAKES 10 // Number of snowflakes in the animation example #define LOGO_HEIGHT 16
#define LOGO_WIDTH 16 String comdata = ""; void oledint(){
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println("SSD1306 allocation failed");
for(;;); // Don't proceed, loop forever
}
Serial.println("success");
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds // Clear the buffer
display.clearDisplay(); // Draw a single pixel in white
display.drawPixel(10, 10, WHITE); // Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(2000); // Invert and restore display, pausing in-between
display.invertDisplay(true);
delay(1000);
display.invertDisplay(false);
delay(1000); }
void setup() {
Serial.begin(9600);
while(Serial.read()>= 0){} //clear serialbuffer
oledint(); } void loop() { if(Serial.available()>0){
delay(100);
comdata = Serial.readString();
// Serial.print("Serial.readString:");
// Serial.println(comdata);
testdrawstyles(comdata);
}
comdata = ""; } String getValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = {0, -1};
int maxIndex = data.length()-1; for(int i=0; i<=maxIndex && found<=index; i++){
if(data.charAt(i)==separator || i==maxIndex){
found++;
strIndex[0] = strIndex[1]+1;
strIndex[1] = (i == maxIndex) ? i+1 : i;
}
} return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
} // x;31.112;y;31.123;z;23.3213;AP1;-23;AP2;-26;AP3;-21
void testdrawstyles(String msg) {
display.clearDisplay(); display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.setCursor(0,0); // Start at top-left corner //display.println(msg);
display.println( "*-------------------*"); String part01 = getValue(msg,';',1);
display.print(F(" X : ")); display.println(part01); String part02 = getValue(msg,';',3);
display.print(F(" Y : ")); display.println(part02); String part03 = getValue(msg,';',5);
display.print(F(" Z : ")); display.println(part03); display.println( " ------------------- ");
String part04 = getValue(msg,';',7);
display.print(F("AP1: ")); display.println(part04); String part05 = getValue(msg,';',9);
display.print(F("AP2: ")); display.println(part05); String part06 = getValue(msg,';',11);
display.print(F("AP3: ")); display.println(part06); display.display();
delay(2000);
}
OLED液晶屏幕(4)串口读取文字并分割,液晶屏幕显示的更多相关文章
- OLED液晶屏幕(3)串口读取文字并分割
https://blog.csdn.net/iracer/article/details/50334041 String comdata = ""; void setup() { ...
- [Arduino] 在串口读取多个字符串,并且转换为数字数组
功能如题目.在串口收到逗号分割的6串数字比如100,200,45,4,87,99然后在6个PWM端口3, 5, 6, 9, 10, 11输出对应PWM值代码注释很详细了,就不再说明了. //定义一个c ...
- Arduino学习笔记A6(补充) - 在串口读取多个字符串,并且转换为数字数组
功能如题目. 在串口收到逗号分割的6串数字比如 100,200,45,4,87,99 然后在6个PWM端口3, 5, 6, 9, 10, 11输出对应PWM值 代码注释很详细了,就不再说明了. ARD ...
- VS编程,C#串口通讯,通过串口读取数据的一种方法
一.可能需要的软件:1.虚拟串口vspd(Virtual Serial Port Driver,用来在电脑上虚拟出一对串口,模拟通讯. 2.友善串口调试助手,用来发送.读取数据. 二.思路1.查询本机 ...
- 一篇提及如何通过串口读取并提取GPS信号的论文
一篇提及如何通过串口读取并提取GPS信号的论文 作者:崔杰 梁计春 王国军 目前,在用计算机进行数据传输时,常用的是串行通信方式.在Visual C++的编程中,既可以用Windows API函数进行 ...
- C# 从串口读取数据
最近要做系统集成,需要从串口读取数据,随学习一下相关知识: 以下是从串口读取数据 public static void Main() { SerialPort mySerialPort = new S ...
- labview初始学习过程中遇到串口读取框红蓝色交替闪烁的处理
labview工程的程序框图VISA串口读取框红蓝交替闪烁,前面板接收数据错乱,或者是接受不了,这是你不小心设置了断点.
- SPLIT(文字列の分割)
概要 SPLIT命令は特定の文字で値を分割する命令だ.タブ区切りや.カンマ区切り等のファイルからデータを取得し値を各項目に振り分けたい時に使用する事が多いだろう.また.XMLファイル等を使用してインタ ...
- Python + opencv 实现图片文字的分割
实现步骤: 1.通过水平投影对图形进行水平分割,获取每一行的图像: 2.通过垂直投影对分割的每一行图像进行垂直分割,最终确定每一个字符的坐标位置,分割出每一个字符: 先简单介绍一下投影法:分别在水平和 ...
随机推荐
- Django-04-路由系统
1. 概述 URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL模式以及 2. path转换器 在django2.0 以上的版本中,默认使用的是path转换器,我们首先以此 ...
- 精通Spring Boot
原 精通Spring Boot—— 第二十一篇:Spring Social OAuth 登录简介 1.什么是OAuth OAuth官网介绍是这样的: An open protocol to allow ...
- oracle基础知识语法大全
ORACLE支持五种类型的完整性约束NOT NULL (非空)--防止NULL值进入指定的列,在单列基础上定义,默认情况下,ORACLE允许在任何列中有NULL值.CHECK (检查)--检查在约束中 ...
- linux 安装Python3.6
1.安装依赖 yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel ...
- linq 注意事项
//linq分组需要注意的是into是在原表的基础上创建新的表进行排序 //new 是新表的字段,可以创建新的字段可以获取当前分组的没一个组的条数 var q = from p in list gro ...
- P1349 广义斐波那契数列(矩阵乘法)
题目 P1349 广义斐波那契数列 解析 把普通的矩阵乘法求斐波那契数列改一改,随便一推就出来了 \[\begin{bmatrix}f_2\\f_1 \end{bmatrix}\begin{bmatr ...
- Python进阶(八)----模块,import , from import 和 `__name__`的使用
Python进阶(八)----模块,import , from import 和 __name__的使用 一丶模块的初识 #### 什么是模块: # 模块就是一个py文件(这个模块存放很多相似的功能, ...
- codeforces Round #568(Div.2)A B C
有点菜,只写出了三道.活不多说,上题开干. A. Ropewalkers Polycarp decided to relax on his weekend and visited to the per ...
- 从客户端中检测到有潜在危险的 Request.QueryString 值
解决办法: 一.解决方法是在web.config的 里面加入<system.web> <pages validateRequest="false"/>< ...
- 模仿jquery--offset方法。原生JS获取任意元素到文档document顶部的距离
1.通过遍历目标节点.目标节点的父节点,依次溯源. 然后累加这些节点到其最近可定位的祖先节点的距离.向上直到document. 其中,需要使用到节点的offsetTop/offsetLeft属性,来获 ...