簡單的讀寫

此示例偵聽通過序列連線進入的輸入,然後將其重新傳送回同一連線。

byte incomingBytes;

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 bytes.
    incomingBytes = Serial.read();

    // Echo the data.
    Serial.println(incomingBytes);
  }
}