def _r_byte(self):
"""
Read byte from the chip.
:return: byte value
:rtype: int
"""
# data pin is now input (pull-down resistor embedded in chip)
GPIO.setup(self._data_pin, GPIO.IN)
# clock the byte from chip
byte = 0
for i in range(8):
# make a high pulse on CLK pin
GPIO.output(self._clk_pin, GPIO.HIGH)
time.sleep(self.CLK_DELAY)
GPIO.output(self._clk_pin, GPIO.LOW)
time.sleep(self.CLK_DELAY)
# chip out data on clk falling edge: store current bit into byte
bit = GPIO.input(self._data_pin)
byte |= ((2 ** i) * bit)
# return byte value
return byte
评论列表
文章目录