write()

描述

从序列埠送出二进制的资料。这些资料是以一个 byte 或连续的 bytes 被送出的;若你想用十进制的方式来传送数字,请改用 print()。

语法


Serial.write(val)
Serial.write(str)
Serial.write(buf, len)

参数

val: 要送出的 byte 值
str: 要送出的字串
buf: 要送出的阵列内容
len: 要送出的阵列内容长度

回传

byte: write() 将回传写到缓冲区内的 byte 数。

范例

void setup(){
  Serial.begin(9600);
}

void loop(){
  Serial.write(45); // 送出一个 byte 值 45,即 00101101

   int bytesSent = Serial.write(“hello”); // 送出字串 “hello” 并且 
                                          // 回传送到缓冲区内的字串长度
}

See also

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


Language Reference Home

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.