发表日期:2016-10-31 17:55:38文章编辑:浏览次数: 标签:
下面的程序,用遥控器上的键和LCD屏,共同构成一个计算器。
#include <LNDZ.h>
lc lcd;
ir irrecv(40);
der results;
void init()
{
lcd.begin(16,2); //开始使用LCD屏
irrecv.start();
winIO; //启用屏幕输出窗口,运行程序时,用tools->Serial monitor查看运行结果
}
long num1=0,num=0;
char f;
long getresult(long x,long y,char c)
{
if (c=='+') return x+y;
else
if (c=='-') return x-y;
}
void repeat()
{
lcd.setCursor(0,0);
if (irrecv.decode(&results))
{
if (results.value == one )
{
num=num*10+1;
lcd.print(num);
}
else
if (results.value == two )
{
num=num*10+2;
lcd.print(num);
}
else
if (results.value == three )
{
num=num*10+3;
lcd.print(num);
}
else
if (results.value == four )
{
num=num*10+4;
lcd.print(num);
}
else
if (results.value == five )
{
num=num*10+5;
lcd.print(num);
}
else
if (results.value == six )
{
num=num*10+6;
lcd.print(num);
}
else
if (results.value == seven )
{
num=num*10+7;
lcd.print(num);
}
else
if (results.value == eight )
{
num=num*10+8;
lcd.print(num);
}
else
if (results.value == nine)
{
num=num*10+9;
lcd.print(num);
}
else
if (results.value==zero)
{
num=num*10;
lcd.print(num);
}
else
if (results.value == th2)
{
f='-';
num1=num;
num=0;
lcd.clear();
}
else
if (results.value == th3)
{
f='+';
num1=num;
num=0;
lcd.clear();
}
else
if (results.value == th1)
{
long n=getresult(num1,num,f);
winprint(n);
lcd.print(n);
num=0;
}
irrecv.next();
}
}