// 设置各引脚别名
const int Talam1_buttonpin = 2; // 连接温度保护开关1引脚
const int Talam2_buttonpin = 3; // 连接温度保护开关2引脚
const int Palam1_buttonpin = 4; // 连接水泵报警引脚
const int P_OUTPin = 5; // 水泵PWM输出引脚
const int H_OUTPin = 6; // 化热器PWM输出引脚
const int T1_analogINPin = A0; // 热电阻模拟量输入引脚
const int T2_analogINPin = A1; // 热电阻模拟量输入引脚
const float BETA1 = 1023; //Pt100-1模拟量
const float BETA2 = 1023; //Pt100-2模拟量
int buttonState1 = 0; // 记录LED1状态
int buttonState2 = 0; // 记录LED2状态
void setup() {
Serial.begin(9600);
// 初始化LED引脚为输出状态
pinMode(Talam1_buttonpin, INPUT_PULLUP);
pinMode(Talam2_buttonpin, INPUT_PULLUP);
pinMode(Palam1_buttonpin, INPUT);
pinMode(P_OUTPin, OUTPUT);
pinMode(H_OUTPin, OUTPUT);
//int T1=0;
//int T2=0;
}
void loop() {
// put your main code here, to run repeatedly:
while(digitalRead(Talam1_buttonpin)==HIGH){
// 当按键按下时,点亮或熄灭LED
if(P_OUTPin==255)
{
analogWrite(P_OUTPin,0);
Serial.print("水泵停止\n");
}
else
{
analogWrite(P_OUTPin,255);
Serial.print("水泵运行\n");
}
}
delay(1000);
while(digitalRead(Talam2_buttonpin)==HIGH){
if(H_OUTPin==255)
{
analogWrite(H_OUTPin,0);
Serial.print("加热停止\n");
}
else
{
analogWrite(H_OUTPin,255);
Serial.print("加热运行\n");
}
}
delay(1000);
int T1= analogRead(T1_analogINPin);
float T3 = 1 / (log(1 / (1023. / T1 - 1)) / 3950 + 1.0 / 298.15) - 273.15;
Serial.print("出水温度");
Serial.print(T3);
Serial.print("℃\n");
delay(2000);
int T2= analogRead(T2_analogINPin);
float T4 = 1 / (log(1 / (1023. / T2 - 1)) / 3950 + 1.0 / 298.15) - 273.15;
Serial.print("回水温度");
Serial.print(T4);
Serial.print("℃\n");
delay(2000);
}