Update i2c_driver.be (#24003)
Added a read_bit function as there is also a write_bit function.
This commit is contained in:
parent
04e0655618
commit
b770518b72
@ -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)
|
||||
|
||||
-#
|
||||
-#
|
||||
|
||||
Loading…
Reference in New Issue
Block a user