Processing, 類I2C
中的read()
用法介紹。
用法
.read(len)
參數
len
(int)
要讀取的字節數
返回
byte[]
說明
從連接的設備讀取字節
您必須在調用此函數之前調用beginTransmission()
。此函數還結束當前傳輸並發送之前使用write()
排隊的任何數據。沒有必要在 read()
之後調用 endTransmission() 。
例子
import processing.io.*;
I2C compass;
void setup() {
//printArray(I2C.list());
compass = new I2C(I2C.list()[0]);
}
void draw() {
// read the heading over I2C from a compass module
// with address 33 (hex 0x21)
compass.beginTransmission(0x21);
// first send a command byte
compass.write(0x41);
// read in two bytes
byte[] in = compass.read(2);
// put bytes together to tenth of degrees
// & 0xff makes sure the byte is not interpreted as a negative value
int deg = (in[0] & 0xff) << 8 | (in[1] & 0xff);
println((deg / 10.0));
}
相關用法
- Processing I2C.beginTransmission()用法及代碼示例
- Processing I2C.list()用法及代碼示例
- Processing I2C.write()用法及代碼示例
- Processing I2C.endTransmission()用法及代碼示例
- Processing I2C.close()用法及代碼示例
- Processing I2C用法及代碼示例
- Processing IntDict.add()用法及代碼示例
- Processing IntDict.values()用法及代碼示例
- Processing IntDict用法及代碼示例
- Processing IntList.get()用法及代碼示例
- Processing IntList.min()用法及代碼示例
- Processing IntList.hasValue()用法及代碼示例
- Processing IntDict.set()用法及代碼示例
- Processing IntDict.sortKeys()用法及代碼示例
- Processing IntDict.sortKeysReverse()用法及代碼示例
- Processing IntDict.increment()用法及代碼示例
- Processing IntList用法及代碼示例
- Processing IntList.shuffle()用法及代碼示例
- Processing IntList.increment()用法及代碼示例
- Processing IntDict.hasKey()用法及代碼示例
- Processing IntList.div()用法及代碼示例
- Processing IntList.size()用法及代碼示例
- Processing IntDict.size()用法及代碼示例
- Processing IntList.max()用法及代碼示例
- Processing IntDict.clear()用法及代碼示例
注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 I2C.read()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。