Serial.read()

名称

Serial.read()

説明

受信したシリアルデータを読む。

Serial.read()は、Streamユーティリティクラスを継承している。

書式

メソッド定義int HardwareSerial::read(void);
利用方法Serial.read();

引数

Serialシリアルポートオブジェクト。

各ボードで利用可能なシリアルポートオブジェクトは、Serialを参照。

戻り値

受信したシリアルデータの最初の1バイト。データがない場合は-1。

使用例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
int incomingByte = 0; // for incoming serial data

void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {
  // send data only when you receive data:
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();

    // say what you got:
    Serial.print("I received: ");
    Serial.println(incomingByte, DEC);
  }
}

参照

オリジナルのページ

https://www.arduino.cc/reference/en/language/functions/communication/serial/read/

Last Revision: 2019/02/21

実装の解析

HardwareSerial::read()

最終更新日

January 4, 2024

inserted by FC2 system