Untitled
unknown
plain_text
a year ago
549 B
4
Indexable
# x728.py import smbus import time bus = smbus.SMBus(0) address = 0x36 def readVoltage(): read = bus.read_word_data(address, 2) swapped = ((read & 0xFF) << 8) | (read >> 8) voltage = swapped * 78.125 / 1000000 return voltage def readCapacity(): read = bus.read_word_data(address, 4) swapped = ((read & 0xFF) << 8) | (read >> 8) capacity = swapped / 256 return capacity while True: print("Voltage: %.2fV" % readVoltage()) print("Capacity: %.2f%%" % readCapacity()) time.sleep(2)
Editor is loading...
Leave a Comment