microbit带有I2C接口,这个驱动演示了通过I2C使用24LCxx读写数据。
代码: 全选
def weep(eepAdr, value):
data = bytearray(3)
data[0]=eepAdr >> 8 #msb
data[1]=eepAdr & 0xFF #lsb
data[2]=value
i2c.write(0x50, data, repeat = False)
sleep(20)
return("OK")
#Read from EEPROM
#Writes the 2 byte memory address to tell the EEPROM where to fetch data from, then reads values from that memory address
#num represents how many sequential bytes to read (default is 1)
def reep(eepAdr, num = 1):
data = bytearray(2)
data[0]=eepAdr >> 8
data[1]=eepAdr & 0xFF
i2c.write(0x50, data)
value = (i2c.read(0x50, num, repeat=False))
return value[:]
adr = 0
for val in font:
weep (adr, val)
adr +=1