OLED液晶屏幕(3)串口读取文字并分割
https://blog.csdn.net/iracer/article/details/50334041

String comdata = "";
void setup() {
Serial.begin(9600);
while(Serial.read()>= 0){} //clear serialbuffer
}
void loop() {
// read data from serial port
if(Serial.available()>0){
delay(100);
comdata = Serial.readString();
Serial.print("Serial.readString:");
Serial.println(comdata);
}
comdata = "";
}

Serial.readStringUntil();
说明
从串口缓存区读取字符到一个字符串型变量,直至读完或遇到某终止字符。
语法
Serial.readStringUntil(terminator)
参数
terminator:终止字符(cha型)
返回
从串口缓存区中读取的整个字符串,直至检测到终止字符。
String comdata = "";
char terminator = ',';
void setup() {
Serial.begin(9600);
while(Serial.read()>= 0){} //clear serialbuffer
} void loop() {
// read data from serial port
if(Serial.available()>0){
delay(100);
comdata =Serial.readStringUntil(terminator);
Serial.print("Serial.readStringUntil: ");
Serial.println(comdata);
}
while(Serial.read()>= 0){}
}
分割函数
https://codeday.me/bug/20181128/417224.html
Web上和stackoverflow上已经存在多个源(例如Split String into String array).
// 1待分割文字
String application_command = "{10,12,13,9,1; 4,5; 2}" // 2分割函数
// https://stackoverflow.com/questions/9072320/split-string-into-string-array
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]) : "";
} // 3调用分割 String part01 = getValue(application_command,';',0);
String part02 = getValue(application_command,';',1);
String part03 = getValue(application_command,';',2);
OLED液晶屏幕(3)串口读取文字并分割的更多相关文章
- OLED液晶屏幕(4)串口读取文字并分割,液晶屏幕显示
ESP8266-07 0.93存 液晶屏 128*64 驱动芯片 ssd1306 接线 VCC-5v GND-GND SCL-D1(SCL) SDA-D2(SDA) 安装两个库 #include & ...
- [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.通过垂直投影对分割的每一行图像进行垂直分割,最终确定每一个字符的坐标位置,分割出每一个字符: 先简单介绍一下投影法:分别在水平和 ...
随机推荐
- 洛谷--P1028 数的计算(递推)
题意:链接:https://www.luogu.org/problem/P1028 先输入一个自然数n (n≤1000) , 然后对此自然数按照如下方法进行处理: 不作任何处理; 在它的左边加上一个自 ...
- DRF框架(七) ——三大认证组件之频率组件、jwt认证
drf频率组件源码 1.APIView的dispatch方法的 self.initial(request,*args,**kwargs) 点进去 2.self.check_throttles(re ...
- LeetCode 5274. Number of Ways to Stay in the Same Place After Some Steps - Java - DP
题目链接:5274. 停在原地的方案数 You have a pointer at index 0 in an array of size arrLen. At each step, you can ...
- Cpp_Primer_4th_Edition-source-code
Cpp_Primer_4th_Edition-source-code 根据书上的去找,官网已经找不到了,毕竟第6版都已经出来了.不过有的朋友用的还是第4版,我的纸质书是第5版,pdf是第4版,都有在看 ...
- Windows查看端口使用状况(转)
转:https://www.cnblogs.com/lixuwu/p/5898354.html 阅读目录 1 查看windows所有端口进程 2 查询指定端口 使用端口是我们在进行远程或者打印机等都会 ...
- 【转载】C#中int.TryParse方法和int.Parse方法的异同之处
在C#编程过程中,int.TryParse方法和int.Parse方法都可以将字符串string转换为整型int类型,但两者还是有区别,最重要的区别在于int.TryParse方法在字符串无法转换为i ...
- 特征选择之FeatureSelector工具
项目地址:https://github.com/WillKoehrsen/feature-selector 特征选择(feature selection)是查找和选择数据集中最有用特征的过程,是机器学 ...
- MySQL分组查询每组最新的一条数据(通俗易懂)
开发中经常会遇到,分组查询最新数据的问题,比如下面这张表(查询每个地址最新的一条记录): sql如下: -- ---------------------------- -- Table structu ...
- Spring的核心机制:依赖注入
依赖注入的概念 当一个对象要调用另一个对象时,一般是new一个被调用的对象,示例: class A{ private B b=new B(); public void test(){ b.say ...
- 如何给SAP云平台购买的账号分配Process Integration服务
在云平台控制台里,给global Account分配Integration Suite下面的Process Integration的API和Runtime两种服务: Process Integrati ...