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()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。