电子说
步骤1:建立电路
什么?您将需要:
-跳线
-16x2 LCD屏幕
-2个电位计
-TMP传感器
-按钮
-LED
步骤2:编写代码
#include
LiquidCrystal lcd(12,11,5,4,4,3,2);
void setup(){
Serial.begin(9600) ;
lcd.begin(16,2);
pinMode(13,OUTPUT);
}
无效循环(){
int tempreading = AnalogRead(0);
int按钮= AnalogRead(1);
int selectC = AnalogRead(2);
selectC = map(selectC,0,1023,12,32);
int selectF =(selectC * 9.0/5.0)+ 32.0;
浮动电压= tempreading * 5.0;电压/=1024.0;
浮点温度C =(电压-0.5)* 100;
浮动温度F =(温度C * 9.0/5.0)+ 32.0;
int加F =温度F + 2; int minusF =温度F-2;
如果(按钮《1023){
lcd.setCursor(0,0);
lcd.print(“ Desired:”);
lcd.print(selectF);
lcd.print( “F”);
lcd.setCursor(0,1);
lcd.print(“ Temp:”);
lcd.print(temperatureF);
lcd.print(“ F”);
}
其他{
lcd.setCursor(0,0);
lcd.print(“ Desired:”);
lcd.print(selectC);
lcd.print( “C”);
lcd.setCursor(0,1);
lcd.print(“ Temp:”);
lcd.print(temperatureC);
lcd.print(“ C”);
}
if(selectF》 = minusF && selectF 《= plusF){
digitalWrite(13,LOW); }其他{
digitalWrite(13,HIGH); } delay(1000);
Serial.println(temperatureF); }
全部0条评论
快来发表一下你的评论吧 !