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.通过垂直投影对分割的每一行图像进行垂直分割,最终确定每一个字符的坐标位置,分割出每一个字符: 先简单介绍一下投影法:分别在水平和 ...
随机推荐
- STC单片机Flash做EEPROM的代码
STC官方给出的建议: /***************************************************************Author:Liming*** * @brie ...
- CSS3弹性盒布局方式
一.CSS3弹性盒子 弹性盒子是CSS3的一种新布局模式. CSS3 弹性盒( Flexible Box 或 flexbox),是一种当页面需要适应不同的屏幕大小以及设备类型时确保元素拥有恰当的行为的 ...
- 【题解】Luogu P5328 [ZJOI2019]浙江省选
原题传送门 看起来挺妙实际很暴力的一题 已知每个选手的分数都是平面上的直线 题目实际就是让我们求每条直线在整点处最大是第几大 我们考虑先对所有的直线进行半平面交(因为\(a_i\)都是正整数,所以比普 ...
- 【题解】Luogu P5304 [GXOI/GZOI2019]旅行者
原题传送门 题意:给你k个点,让你求两两最短路之间的最小值 我们考虑二进制拆分,使得每两个点都有机会分在不同的组\((A:0,B:1)\)中,从源点\(S\)向\(A/B\)中的点连边权为0的边,从\ ...
- 一些spring boot的配置
RabbitMQ与Redis队列对比 https://www.cnblogs.com/chinaboard/p/3819533.html Spring batch的学习 https://www.cnb ...
- Java File类 mkdir 不能创建多层目录
File f = new File("/home/jp/Upload"); if ((!f.exists()) || (!f.isDirectory())) {boolean re ...
- MyBatis返回结果类型为Boolean
问题描述: 在使用MyBatis时,有时需要检查某个记录是否存在数据库中,然后根据其返回的布尔值true or false,来进行逻辑判断.那怎么做呢? 解决方案: 如检测某个手机号是否 ...
- ArcGIS加载数据中常用的File文件方法总结
在介绍ArcGIS中各种数据的打开方法时,我们用到了许多对于File文件的操作,在此做一个常用用法的总结.例如, 介绍ArcGIS中各种数据的打开方法——mxd(地图文档) 以方法一为例:运用Load ...
- window 包管理器--Chocolatey
Chocolatey 介绍 在 Linux 下,大家喜欢用 apt-get 来安装应用程序,如今在 windows 下,大家可以使用 Chocolatey 来快速下载搭建一个开发环境. Chocola ...
- Python基础知识(四)
Python基础知识(四) 一丶列表 定义格式: 是一个容器,由 [ ]表示,元素与元素之间用逗号隔开. 如:name=["张三","李四"] 作用: 存储任意 ...