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()
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.