HT16K33的16X8LED点阵在PYBoard
HT16K33的16X8LED点阵
HT16K33中文资料
HT16K33命令:
0x21/0x20(系统内部振荡器开启/关闭)
0x81/0x80(显示开启/关闭)
测试程序
from pyb import I2C i2c=I2C(2,I2C.MASTER)#PYB上有2条I2C,1号在X9,X10脚。2号在Y9,Y10。 i2c.init(I2C.MASTER,baudrate=400000)#时钟频率最大400KHz i2c.send(0x21,0x21)#系统内部振荡器开启 for i in range(16): i2c.mem_write(0,0x70,i)#所有LED清零。第一个0是数据,0-255,8个LED的所有组合。0x70是I2C地址。i是寄存器地址(0-15)。 i2c.send(0x81,0x21)#显示开启 for i in range(16): i2c.mem_write(255,0x21,i)#点亮所有LED python脚本: from mpython import * addr = 112 #命令数据为16位的后8位D8-d15,实际地址需加1 #i2c.writeto_mem(addr, 0x00, bytearray([25])) i2c.writeto(addr, b'\x21') #使能工作 i2c.writeto(addr, b'\x21') i2c.writeto(addr, b'\xE1') #亮度 i2c.writeto(addr, b'\xE0') i2c.writeto(addr, b'\xA1') i2c.writeto(addr, b'\xA0') # i2c.writeto(addr, b'\xD9') #测试 # i2c.writeto(addr, b'\xD9') i2c.writeto(addr, b'\x81') #使能显示 i2c.writeto(addr, b'\x81') show = 0 while True: #print(i2c.scan()) for i in range(16): show = show+1 i2c.writeto_mem(addr, i, bytearray([0xFF])) time.sleep(1) for i in range(16): i2c.writeto_mem(addr, i, bytearray([0X00])) time.sleep(1)
赞 (0)