当前位置:网站首页>Summary of Arduino serial functions related to print read
Summary of Arduino serial functions related to print read
2022-07-03 07:19:00 【yuchu3d】
To sum up I'm learning arduino srial Function time A few knowledge points of :
/**
* Put it together Serial.print Some situations of output , The latter part should be connected with Serial.read In combination with ;
* 1. print The output characters and int Number of results ,
* 2. print Output string and a series of numbers
* 3. read Read a character Then the output
* 4. read Read a number Then the output
* 5. How to read multiple numbers and then output
* 6. How to read multiple characters and then output
*/
char charDanzifu = 'a';
int intXiaozhengshu1 = 9;
int intXiaozhengshu2 = 19;
int intDazhengshu1= 0X1111;
int intDazhengshu2 = 0X22221;
char intChar1 = 16;
char intChar2 = 98;
char charShuzu1[]="Hello world!";
char charShuzu2[]="98 97 99 100";
void setup()
{
Serial.begin(9600);
Serial.println(charDanzifu); // charDanzifu It's just a character ,print With ASCII Code form output ,IDE When the serial port monitor displays , Turn into ASCII The character corresponding to the code is displayed
Serial.println(intXiaozhengshu1); // Numbers are also output in the form of characters , The output is 9 character Corresponding ASCII code , On display It is shown that ASCII The character corresponding to the code
Serial.println(intXiaozhengshu2); // 19 yes It is divided into character 1 and character 9 , Transmitted and displayed separately
Serial.println(intDazhengshu1,HEX); // The integer form is normal output , If you don't take HEX , It defaults to decimal output ,
Serial.println(intDazhengshu2,HEX); // Pay attention here ,0X22221 More than the 16 position ,Arduino UNO Maximum storage 16 position , exceed 16 position , Truncation occurs , You can see that one is missing in the output result 2
Serial.println(intChar1); // If you use numbers 16 Express char Format , The program will default 16 Is a character ASCII code ,
// When outputting The output is this number , This code is displayed Corresponding characters , 16 Corresponding characters It's garbled
Serial.println(intChar2); // 98 The corresponding character is b, So the final output is b
Serial.println(charShuzu1); // Normal output string
Serial.println(charShuzu2); // The numeric string is also in accordance with Single Numeric character Output in sequence
}
/**
*
* The following is loop Medium test read and print Corresponding output
1. Direct use read Without variable output
2. The variable defined is char type , stay read In the case of characters and numbers , What are the outputs respectively
3. The variable defined is int type , stay read In the case of characters and numbers , What are the outputs respectively
4. How to read a long integer , Then output it correctly ( All in decimal )
5. How to read a long string , Then output it correctly
*/
void loop() // For each category , A single module , it is to be noted that delay.
{
// read and print
int intReadp = 0;
char charReadp;
while(!Serial.available()){}
while(Serial.available())
{
// read Read only one byte at a time , And remove from the cache ; Check it out here Direct output read What's the result , No variables , Input 6a
Serial.println(" First step :");
Serial.println(Serial.read());
delay(10);
}
while(!Serial.available()){}
while(Serial.available())
{
// read Read only one byte at a time , And remove from the cache ; Check it out here int Type variable stay int and char Type to read the output results separately , Input 6a
intReadp = Serial.read();
Serial.println(" The second step :");
Serial.print(" The intReadp is : ");
Serial.println(intReadp);
delay(10);
}
while(!Serial.available()){}
while(Serial.available())
{
// Check it out here char Type variable stay int and char Type to read the output results separately , Input 6a
charReadp = Serial.read();
Serial.println(" The third step :");
Serial.print(" The charReadp is : ");
Serial.println(charReadp);
delay(10);
}
/* How to read a long string of numbers , Such as input 1234 , Read this number , Then the output 1234
* You need a character array to receive each numeric character separately , Be careful , To get the same character as the original input character , Need to use char Format to store read Data to
*/
String chuanString ="";
char inChar;
while(!Serial.available()){}
while(Serial.available())
{
// Input 1234
inChar = Serial.read();
chuanString += inChar;
delay(10);
}
Serial.println(" Step four :");
Serial.print(" The chuanString is : ");
Serial.println(chuanString);
int intChuanshu = chuanString.toInt(); // Ahead chuanString It's a string format , We want to get the number , When integers are used , Need to convert , use toInt, After transformation , It becomes an integer
Serial.println(" Step four The second :");
Serial.print(" The intChuanshu is : ");
Serial.println(intChuanshu);
intChuanshu = intChuanshu+7;
Serial.println(" Step four A third :");
Serial.print(" The intChuanshu Add is : ");
Serial.println(intChuanshu);
String chuanString2 ="";
char inChar2;
while(!Serial.available()){}
while(Serial.available())
{
// Input abcdefg
inChar2 = Serial.read();
chuanString2 += inChar2;
delay(10);
}
Serial.println(" Step five :");
Serial.print(" The chuanString2 is : ");
Serial.println(chuanString2);
delay(2000);
}
Input separately : 6a 6a 6a 1234 absdf after ( Serial port display box The lower right choose No terminator )
The operation results are as follows :
边栏推荐
- JMeter test result output
- sharepoint 2007 versions
- In depth analysis of reentrantlock fair lock and unfair lock source code implementation
- C code production YUV420 planar format file
- Use the jvisualvm tool ----- tocmat to start JMX monitoring
- Pits encountered in the use of El checkbox group
- Pat grade a real problem 1166
- Notes on the core knowledge of Domain Driven Design DDD
- Warehouse database fields_ Summary of SQL problems in kingbase8 migration of Jincang database
- 【已解决】SQLException: Invalid value for getInt() - ‘田鹏‘
猜你喜欢
docker建立mysql:5.7版本指定路径挂载不上。
"Baidu Cup" CTF game 2017 February, Web: blast-1
New stills of Lord of the rings: the ring of strength: the caster of the ring of strength appears
[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet
C code production YUV420 planar format file
Deep learning parameter initialization (I) Xavier initialization with code
在 4EVERLAND 上存储 WordPress 媒体内容,完成去中心化存储
Reading notes of "learn to ask questions"
Selenium key knowledge explanation
JMeter test result output
随机推荐
Reading notes of "learn to ask questions"
Docker builds MySQL: the specified path of version 5.7 cannot be mounted.
Book recommendation~
[day15] introduce the features, advantages and disadvantages of promise, and how to implement it internally. Implement promise by hand
Operation and maintenance technical support personnel have hardware maintenance experience in Hong Kong
Use of framework
《指环王:力量之戒》新剧照 力量之戒铸造者亮相
Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
4279. 笛卡尔树
Sorting out the core ideas of the pyramid principle
The difference between typescript let and VaR
PHP install composer
"Baidu Cup" CTF game 2017 February, Web: blast-1
Le Seigneur des anneaux: l'anneau du pouvoir
La différence entre le let Typescript et le Var
Discussion on some problems of array
Selenium key knowledge explanation
Strategy mode
Split small interface
Common problems in io streams