read()

描述

读取序列埠收到的资料。read() 是继承于 Stream 类别。

语法

适用所有板子:

Serial.read()
Serial1.read()

适用 86Duino ONE:

Serial2.read()
Serial3.read()
Serial485.read()

适用 86Duino EduCake:

Serial2.read()
Serial3.read()
Serial232.read()

参数

æ—

回传

读取传进来的 byte 值 (假如没有收到任何资料,则回传 -1) int 型别

范例

int incomingByte = 0;   // 储存值的变数

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

void loop() {

        // 只有在收到值的时候才送资料
        if (Serial.available() > 0) {
                // 读取传送进来的 byte:
                incomingByte = Serial.read();

                // 说你收到了什么
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
        }
}

See also

- Serial
- available()
- begin()
- end()
- find()
- findUntil()
- flush()
- parseFloat()
- parseInt()
- peek()
- print()
- println()
- 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.