您的位置:首页 > 产品设计 > UI/UE

20141115 【 Arduino - LM35 - 4位八段数码管 】 数码管显示温度

2014-11-15 12:01 417 查看
4位八段数码管型号:SMA420564

引脚图如下:



通过公式,转换成温度值(摄氏度,精确到小数点后一位)。

不过 LM35 之前被我正负极反接,

结果温度升的奇高(手测超过80°C),

不知道有没有烧坏。(好像还能用吧!!!)

const int pinLM = A5;

const int Vmax = 625;	//5000:1024
const int LMmax = 128;

const int pinChoose[4] = {10,11,12,13};
const int pinLCD[8] = {2,3,4,5,6,7,8,9};
const int num[17] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71, 0x80};
// 0123456789 AbCdEF.  + 17

int flash = 2;			//工作指示灯

void setup()
{
pinMode(pinLM, INPUT);
for(int i=0; i<4; i++)
pinMode(pinChoose[i], OUTPUT);
for(int i=0; i<8; i++)
pinMode(pinLCD[i], OUTPUT);
Serial.begin( 9600 );
}

void loop()
{
unsigned int t = analogRead(pinLM);
t = t*Vmax/LMmax;
Serial.println( t );
for(int i=200; i; i--){
show_t( t );	//数码管显示温度
}
flash = ~flash;		//工作指示灯 闪烁
}

void show_num(int nx){
for(int i=0; i<8; i++)
digitalWrite(pinLCD[i], ((1<<i)&nx));
}

void show_t(int x){
for(int i=3; i>=0; i--){
digitalWrite(pinChoose[i], LOW);
if( x )
if( i==flash )	show_num( num[x%10]|0x80 );
else			show_num( num[x%10] );
else		show_num( 0x00 );
delay(1);
show_num( 0x00 );		//消影

x /= 10;
digitalWrite(pinChoose[i], HIGH);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: