温度传感器的最大值和最小值

问题描述 投票:-1回答:1

((参考最后一个if语句)我这里有一些代码,使我始终将T_High与T保持相同。如果我正在寻找代码所见的最高温度,我不确定是否需要添加另一个变量并调整我的代码或当前的问题是什么。我尝试过在线查询最大和最小时间,但是即使有多个来源,我也无法使其正常工作。我知道在我的if语句之后,我让它们彼此相等,但是我认为if语句会解决这个问题。这是在粒子IDE中(非常类似于Arduino)。

#include <math.h>
const int thermistor_output = A1;

void setup() {
Serial.begin(9600); 
}

void loop() {

float T_Low = 999;
float T_High;

int x=0;
int thermistor_adc_val;
double a,b,c,d,e,f,g,h,i,j,T;
double output_voltage, thermistor_resistance, therm_res_ln, temperature_celsius;
while (x < 10 )
{
thermistor_adc_val = analogRead(thermistor_output);
output_voltage = ( (thermistor_adc_val * 3.3) / 4095.0 );
thermistor_resistance = ( ( 3.3 * ( 10.0 / output_voltage ) ) - 10 ); /* Resistance in kilo ohms */
thermistor_resistance = thermistor_resistance * 1000 ; /* Resistance in ohms   */
therm_res_ln = log(thermistor_resistance);
  /*  Steinhart-Hart Thermistor Equation: */
  /*  Temperature in Kelvin = 1 / (A + B[ln(R)] + C[ln(R)]^3)   */
  /*  where A = 0.001129148, B = 0.000234125 and C = 8.76741*10^-8  */
temperature_celsius = ( 1 / ( 0.001129148 + ( 0.000234125 * therm_res_ln ) + ( 0.0000000876741 * therm_res_ln * therm_res_ln * therm_res_ln ) ) ); /* Temperature in Kelvin */
temperature_celsius = temperature_celsius - 273.15; /* Temperature in degree Celsius */
T = temperature_celsius * 1.8 + 29; /* Temperature in degree Fahrenheit */

delay(100);

 x ++ ;
 if (x==1){a=T;}
 if (x==2){b=T;}
 if (x==3){c=T;} 
 if (x==4){d=T;}
 if (x==5){e=T;}
 if (x==6){f=T;}
 if (x==7){g=T;}
 if (x==8){h=T;}
 if (x==9){i=T;}
 }

j=a+b+c+d+e+f+g+h+i;
T=j/9;
 x=0; 

delay(2000);

if (T > T_High) {
        T_High = T;
}

Particle.publish ("Temp", String(T));
Particle.publish ("High", String(T_High));
}
`

((参考最后一个if语句)我在这里有一些代码,使我始终将T_High与T保持相同。如果我正在寻找代码所看到的最高温度,我不确定是否...

c++ arduino
1个回答
0
投票

T_Highloop()中的局部变量。它仅在loop()功能退出之前存在。在下一次迭代中,将存在T_High变量的new

© www.soinside.com 2019 - 2024. All rights reserved.