Arduino参考

Arduino参考 > Libraries > SoftwareSerial > write()

SoftwareSerial.write()

Prints data to the transmit pin of the SoftwareSerial object as raw bytes. Works the same as the Serial.write()function.

Syntax

mySerial.write(val)

Parameters

  • val: the binary value to print.

Returns

The number of bytes written (reading this number is optional).

Example

#include <SoftwareSerial.h>

// Set up a new SoftwareSerial object with RX in digital pin 10 and TX in digital pin 11
SoftwareSerial mySerial(10, 11);

void setup() {
    // Set the baud rate for the SerialSoftware object
    mySerial.begin(9600);
}

void loop() {
    // Send a byte with the value 45
    mySerial.write(45);

    //Send the string “hello” and return the length of the string.
    int bytesSent = mySerial.write(“hello”);
}