println()

描述

透过序列埠印出具有阅读性的 ASCII 文字,后面再接着回车字元 (ASCII 13 或 \r) 和新列字元 (ASCII 10 或 \n)。这个函式和 Serial.print() 有相同的格式。

语法


Serial.println(val)
Serial.println(val, format)

参数

val: 要印的值 任意型别
format: 指定印出的格式 (对于整数的资料型别) 或小数点后的位数 (对于符点数资料型别)

回传

size_t (long):print() 的 byte 数

范例

/*
  类比讯号输入

 从类比讯号脚 0 读取类比讯号,然后印出读到的值

 created 24 March 2006
 by Tom Igoe
 */

int analogValue = 0;    // 储存类比值的变数

void setup() {
  // 设定 Serial 为 9600 鲍率
  Serial.begin(9600);
}

void loop() {
  // read the analog input on pin 0:
  analogValue = analogRead(0);

  // print it out in many formats:
  Serial.println(analogValue);       // 印出十进位格式的数字
  Serial.println(analogValue, DEC);  // 印出十进位格式的数字
  Serial.println(analogValue, HEX);  // 印出十六进位格式的数字
  Serial.println(analogValue, OCT);  // 印出八进位格式的数字
  Serial.println(analogValue, BIN);  // 印出二进位格式的数字

  // 延迟 10 毫秒后再读取类比讯号
  delay(10);
}

See also

Serial
available()
begin()
end()
find()
findUntil()
flush()
parseFloat()
parseInt()
peek()
print()
read()
readBytes()
readBytesUntil()
setTimeout()
write()
serialEvent()


语法参考主页面

The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.