shiftIn()

描述

以 byte 為單位來接收資料,一次一個 bit。可以從最高或者最低有效位元開始接收資料;接收每一個 bit 的過程中,時脈 pin 腳會先被拉成高電位,然後從資料 pin 上讀取一個 bit,再將時脈 pin 腳拉成低電位。

注意:如果你使用的裝置是屬於正緣觸發的類型,你需要確定時脈 pin 腳在呼叫 shiftOut() 之前是處於低電位的狀態,例:可以呼叫 digitalWrite(clockPin, LOW) 將 pin 腳設定為低電位

這個函式是以軟體模擬方式實作的,可以參考 SPI 函式庫,它提供了一個高效的硬體實作方式,但只能作用在某些固定的 pin 腳上。

語法


byte incoming = shiftIn(dataPin, clockPin, bitOrder)

參數

dataPin: 要讀取 bit 的 pin 腳 (int)
clockPin: 要輸出時脈的 pin 腳 (int)

bitOrder: 讀取 bit 的順序,不是 MSBFIRST 就是 LSBFIRST (從最高或最低有效位元開始讀取)

回傳

讀取到的數值 (byte)

See also

shiftIn()
SPI


語法參考主頁面

本頁由熱血青年 LBU 譯自英文版。

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.