| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #ifndef NtcThermistor_h
- #define NtcThermistor_h
- #include <Arduino.h>
- class NtcThermistor {
- private:
- // NTC引脚
- const int _pin1;
- const int _pin2;
- const int _pin3;
-
- // NTC参数 - 可根据实际元件修改
- const float _referenceResistance; // 参考电阻值(欧姆)
- const float _ntcNominalResistance; // NTC在标称温度下的电阻(欧姆)
- const float _ntcBetaValue; // NTC的Beta值
- const float _referenceTemperature; // 标称温度(摄氏度,通常为25°C)
- const int _adcResolution; // ADC分辨率(如10位=1024)
-
- // 温度存储
- float _temperature1;
- float _temperature2;
- float _temperature3;
-
- // 读取单个NTC温度的内部方法
- float readTemperature(int pin);
-
- public:
- // 构造函数
- NtcThermistor(int pin1, int pin2, int pin3,
- float referenceResistance = 10000.0,
- float ntcNominalResistance = 10000.0,
- float ntcBetaValue = 3950.0,
- float referenceTemperature = 25.0,
- int adcResolution = 4095); // ESP32默认ADC分辨率
-
- // 更新所有温度读数
- void updateTemperatures();
-
- // 获取温度值
- float getTemperature1();
- float getTemperature2();
- float getTemperature3();
-
- // 获取格式化的温度字符串
- String getTemperature1String();
- String getTemperature2String();
- String getTemperature3String();
- };
- #endif
|