数码管

来自Labplus盛思维基百科
Tangliufeng讨论 | 贡献2017年12月27日 (三) 11:35的版本 技术参数
跳转至: 导航搜索
数码管-01.png

概述

4位7段LED数码管显示,可显示整形数字

技术参数

  • 工作电压:VCC 3.3-5V
  • 接口方式:I2C接口
  • 模块尺寸:24x46x7.5mm

引脚定义

VCC 电源
SDA I2C数据
SCL I2C时钟
GND

使用教程

连接示意图

Arduino示例

MicroPython示例

from microbit import *

_TubeTab = [
    0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 
    0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71, 0x00, 0x40]

def tm1650Init():
  i2c.write(0x24, bytearray([0x01]))
def tm1650DisplayUint(x):
  charTemp = [0, 0, 0, 0]
  x = (x if x < 10000 else 9999)
  charTemp[3] = x%10
  charTemp[2] = (x//10)%10
  charTemp[1] = (x//100)%10
  charTemp[0] = (x//1000)%10
  if x < 1000:
    charTemp[0] = 0x10
    if x < 100:
      charTemp[1] = 0x10
      if x < 10:
        charTemp[2] = 0x10
  for i in range(0, 4):
    i2c.write(0x34+i, bytearray([_TubeTab[charTemp[i]]]))
def tm1650DisplayInt(x):
  x = round(x)
  if x >= 0:
    tm1650DisplayUint(x)
  else:
    temp = (x if x > -999 else -999)
    temp = abs(temp)
    tm1650DisplayUint(temp)
    if temp < 10:
      i2c.write(0x36, bytearray([_TubeTab[0x11]]))
    elif temp < 100:
      i2c.write(0x35, bytearray([_TubeTab[0x11]]))
    elif temp < 1000:
      i2c.write(0x34, bytearray([_TubeTab[0x11]]))

tm1650Init()

display.off()
while True:
    tm1650DisplayInt(7777)
    sleep(1000)
    tm1650DisplayInt(8888)
    sleep(1000)
    tm1650DisplayInt(9999)
    sleep(1000)
    tm1650DisplayInt(1111)
    sleep(1000)


图形化示例