4位数码管模块

来自YFRobotwiki
2019年12月26日 (四) 09:42Allblue讨论 | 贡献的版本

跳转至: 导航搜索
生成缩略图出错:文件可能丢失:
4位数码管


产品简介


4位数码管模块是采用0.56英寸4位数码管设计制作,有小数点、时钟两种模式可选择,采用PH2.0-4P接口/XH2.54-4P排针接口,配合专用传感器线使用方便接线;且有M3安装柱可选配,方便固定。

将4位数码管模块加入项目中,可用来显示数值、时钟等信息。


规格参数


  • 数码管:0.56 英寸,4 位
  • 驱动IC:TM1650
  • 工作电压 3V~5V
  • 工作温度:-40℃~80℃
  • 亮度等级:8 级亮度可设置
  • 模块尺寸:50.5mm * 19.5mm
  • 安装孔:3mm
  • 安装孔中心距:42mm * 12mm
  • 模块重量:3.8g


引脚说明


  • 1. GND 黑线 -- Gnd(地)
  • 2. VCC 红线 -- Vcc(电源+5V)
  • 3. CLK 蓝线 -- 信号
  • 3. DIO 白线 -- 信号


应用示例


电路连接示意图


4位数码管显示模块 Arduino UNO
VCC +5V
GND GND
CLK D10
DIO D11



4位数码管显示

提示:以下程序需使用到 tm1650库文件,文件下载地址见页末 - 参考资料。下载后将其解压至arduinoIDE安装目录/libraries文件夹中,例如: "D:\Program Files\Arduino\arduino-1.6.4-windows\arduino-1.6.4\libraries"。

示例代码

示例一:4位数码管显示测试

TM1650库文件

/*------------------------------------------------------------------------------------

   TM1650 nixie tube

   This example code shows how to use the functions of the TM1650 Library.

  -------------------------------------------------------------------------------------*/
/*************************************************************************************/

#include<tm1650.h>

#define ON	DISPLAY_ON
#define OFF	DISPLAY_OFF
#define SegmentMode		_8_SEGMENT_MODE
unsigned char  LightLevel = LV2;
unsigned char  WorkMode = NORMAL_MODE;

//define each segment
const unsigned char  Seg_test[8] =      {0x20, 0x01, 0x02, 0x04, 0x08, 0x10, 0x40, 0x80};
//number 0-9 code
const unsigned char Number_arr[10] =   {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};

unsigned char i, j = 0, k = 0, l = 0, m = 0;
unsigned char temp[4] = {0x3f, 0x06, 0x5b, 0x4f};
boolean err = 0;

int	pin_SCK = 10;
int	pin_DIO = 11;

TM1650 tm1650(pin_SCK, pin_DIO);

void setup()
{

}

void loop()
{

  //config tm1650
  err = tm1650.DisplayConfig_TM1650(LightLevel, SegmentMode, WorkMode, ON);
  //all nixie tube turn on
  for (i = 0; i < 4; i++)
  {
    err = tm1650.DisplayOneDigi_TM1650(i + 1, 0xFF);
  }
  delay(500);

  //loop each segment
  for (m = 0; m < 8; m++)
  {
    for (i = 0; i < 4; i++)
    {
      err = tm1650.DisplayOneDigi_TM1650(i + 1, Seg_test[m]);
    }
    delay(500);
  }

  //display form 0 to 9
  for (m = 0; m <= 9; m++)
  {
    for (i = 0; i < 4; i++)
    {
      err = tm1650.DisplayOneDigi_TM1650(i + 1, Number_arr[m]);
    }
    delay(500);
  }
  //display the content of array temp[]
  for (i = 0; i < 4; i++)
  {
    err = tm1650.DisplayOneDigi_TM1650(i + 1, temp[i]);
  }
  delay(500);

  //all turn off
  err = tm1650.DisplayOFF_TM1650(LightLevel, SegmentMode, WorkMode);
  delay(1000);

  //turn on again
  err = tm1650.DisplayON_TM1650(LightLevel, SegmentMode, WorkMode);
  delay(1000);
}

程序下载地址:TM1650_nixie_tube

程序运行结果:根据显示效果看程序,更方便理解




示例二:电位器控制彩色LED模块变色
电路连接示意图

potentiometer2


/*
  Potentiometer control RGB LED change color
*/

#include <Adafruit_NeoPixel.h>

#define RGBLEDPin  5
#define NUMPIXELS  4
#define pPin  A0

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, RGBLEDPin, NEO_GRB + NEO_KHZ800);

int pVal = 0;
int RVal = 0;
int GVal = 0;
int BVal = 0;

void setup()
{
  pinMode(RGBLEDPin, OUTPUT);
  pixels.begin(); // This initializes the NeoPixel library.
  pixels.show();
}

void loop()
{
  pVal = analogRead(pPin);    //读取A0模拟口的数值(0-5V 对应 0-1203取值)
  if (pVal >= 0 && pVal <= 170) {
    RVal = 255;
    GVal = 0;
    BVal = map(pVal, 0, 170, 0, 255);
  } else if (pVal > 170 && pVal <= 340) {
    RVal = map(pVal, 170, 340, 255, 0);
    GVal = 0;
    BVal = 255;
  } else if (pVal > 340 && pVal <= 510) {
    RVal = 0;
    GVal = map(pVal, 340, 510, 0, 255);
    BVal = 255;
  } else if (pVal > 510 && pVal <= 680) {
    RVal = 0;
    GVal = 255;
    BVal = map(pVal, 510, 680, 255, 0);
  } else if (pVal > 680 && pVal <= 850) {
    RVal = map(pVal, 680, 850, 0, 255);
    GVal = 255;
    BVal = 0;
  } else {
    RVal = 255;
    GVal = map(pVal, 850, 1023, 255, 0);
    BVal = 0;
  }
  lightLED(RVal, GVal, BVal);
}

void lightLED(int r, int g , int b) {
  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
  for (int i = 0; i < NUMPIXELS; i++) {
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, r, g, b); // Moderately bright green color.
    pixels.show(); // This sends the updated pixel color to the hardware.
  }
}

程序下载地址:ChangeColor

程序运行结果:转动电位器,彩色led变色。






返回首页

更多建议和问题欢迎反馈至 YFRobot论坛

购买方式:YFRobot 电子工作室