Understanding How Arduino Serial Port Send Line Feed LF, Carriage Return CR and New Line Character
https://elextutorial.com/learn-arduino/arduino-serial-port-send-line-feed-carriage-return-new-line/
尚未解决的问题:
情况一:Serial.read()串口数据读取 串口中可读取数据的第一个字节(如果没有可读取的数据则返回-1)。该返回值为整数型,返回值内容是读取到数据的ASCII代码。
void setup()
{
Serial.begin(115200); // Set the baud rate to 9600
}
void loop()
{
if(Serial.available()) // Check if received
{
int data1 = Serial.read(); // Read if received
Serial.println(data1); // Send back to PC/Laptop
}
}
情况二:Serial.parseFloat()串口数据读取 在输入信息中找到浮点数值。类型:float
void setup()
{
Serial.begin(115200); // Set the baud rate to 9600
}
void loop()
{
if(Serial.available()) // Check if received
{
float data1=Serial.parseFloat();// Read if received
Serial.println(data1); // Send back to PC/Laptop
}
}
疑问:如何在输出显示12的同时正确输出Terminator?
|