Unverified Commit f3763164 authored by Luc's avatar Luc Committed by 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
parent 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%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment