Update i2c_driver.be (#24003)

Added a read_bit function as there is also a write_bit function.
This commit is contained in:
vrilcode 2025-10-12 15:26:26 +02:00 committed by GitHub
parent 04e0655618
commit b770518b72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -118,10 +118,17 @@ class I2C_Driver
var buf = self.wire.read_bytes(self.addr, reg, 4)
return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3]
end
# Reads a specific bit from a register
# read_bit(reg:int, bit:int) -> bool
def read_bit(reg, bit)
if bit < 0 || bit > 7 return end
return bool(self.read8(reg) & 1 << bit)
end
end
#- Example
d = I2C_Driver("MPU", 0x68, 58)
-#
-#