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

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);
	}
}







  • 2
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值