Serial.write()

[Serial]

描述

Writes binary data to the serial port. This data is sent as a byte or series of bytes; to send the characters representing the digits of a number use the print() function instead.

語法

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

參數

  • val: a value to send as a single byte
  • str: a string to send as a series of bytes
  • buf: an array to send as a series of bytes
  • len: the length of the buffer

回傳

byte: write() will return the number of bytes written, though reading that number is optional

範例

void setup(){
  Serial.begin(9600);
}
 
void loop(){
  Serial.write(45); // send a byte with the value 45
 
   int bytesSent = Serial.write("hello"); // send the string "hello" and 
                                          // return the length of the string.
}

參考


語法參考主頁面

86Duino 參考的文本是根據 Creative Commons Attribution-ShareAlike 3.0 License,部分文本是從 the Arduino reference 修改的。 參考中的代碼示例已發佈到公共領域。

發表評論

上部へスクロール