Hi,
i have a problem with understanding the zero shift in byte information.
If I have "byte = B11111111" than "bitRead(byte, 0)" is 1.
If I have "byte = B11111110" than "bitRead(byte, 0)" is bug.
uint16_t data_r;
uint16_t data_old;
uint8_t val[15];
uint8_t val_old[15];
...
Wire.beginTransmission(address);
Wire.requestFrom(address, 2);
if (Wire.available()) {
uint8_t lo = Wire.read();
uint8_t hi = Wire.read();
data_r = (word(hi, lo));
if (data_r != data_old) {
for (uint8_t i = 0; i < 16; i++) {
val[i] = (bitRead(data_r, i ));
if (val[i] != val_old[i]) {
Serial.print("button: ");
Serial.println(i);
Serial.print("value: ");
Serial.println(val[i]);
Serial.print("data: ");
Serial.println(data_r, BIN);
val_old[i] = val[i];
}
}
data_old = data_r;
}
delay(100);
}
Is it possible to work with zero as a number without omitting a position?
The problem is 0 and 15, the result of the code for val[0] and val[15] at byte = B11111110 (byte = B01111111) is wrong. I think the code omit zero as a number if it is at the beginning or end of the value byte.
The problem is 0 and 15, the result of the code for val[0] and val[15] at byte = B11111110 (byte = B01111111) is wrong. I think the code omit zero as a number if it is at the beginning or end of the value byte.