未验证 提交 f3763164 编写于 作者: L Luc 提交者: GitHub

WireMaster example clarity (#6844)

- Created new temporary variable, stopping confusion with the reuse of "error". As Wire.requestFrom() doesn't return an error.
- Added a cast to help clarify when and why bytes are being read
上级 53698aef
......@@ -20,11 +20,11 @@ void loop() {
Serial.printf("endTransmission: %u\n", error);
//Read 16 bytes from the slave
error = Wire.requestFrom(I2C_DEV_ADDR, 16);
Serial.printf("requestFrom: %u\n", error);
if(error){
uint8_t temp[error];
Wire.readBytes(temp, error);
log_print_buf(temp, error);
uint8_t bytesReceived = Wire.requestFrom(I2C_DEV_ADDR, 16);
Serial.printf("requestFrom: %u\n", bytesReceived);
if((bool)bytesReceived){ //If received more than zero bytes
uint8_t temp[bytesReceived];
Wire.readBytes(temp, bytesReceived);
log_print_buf(temp, bytesReceived);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册