NtcThermistor.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef NtcThermistor_h
  2. #define NtcThermistor_h
  3. #include <Arduino.h>
  4. class NtcThermistor {
  5. private:
  6. // NTC引脚
  7. const int _pin1;
  8. const int _pin2;
  9. const int _pin3;
  10. // NTC参数 - 可根据实际元件修改
  11. const float _referenceResistance; // 参考电阻值(欧姆)
  12. const float _ntcNominalResistance; // NTC在标称温度下的电阻(欧姆)
  13. const float _ntcBetaValue; // NTC的Beta值
  14. const float _referenceTemperature; // 标称温度(摄氏度,通常为25°C)
  15. const int _adcResolution; // ADC分辨率(如10位=1024)
  16. // 温度存储
  17. float _temperature1;
  18. float _temperature2;
  19. float _temperature3;
  20. // 读取单个NTC温度的内部方法
  21. float readTemperature(int pin);
  22. public:
  23. // 构造函数
  24. NtcThermistor(int pin1, int pin2, int pin3,
  25. float referenceResistance = 10000.0,
  26. float ntcNominalResistance = 10000.0,
  27. float ntcBetaValue = 3950.0,
  28. float referenceTemperature = 25.0,
  29. int adcResolution = 4095); // ESP32默认ADC分辨率
  30. // 更新所有温度读数
  31. void updateTemperatures();
  32. // 获取温度值
  33. float getTemperature1();
  34. float getTemperature2();
  35. float getTemperature3();
  36. // 获取格式化的温度字符串
  37. String getTemperature1String();
  38. String getTemperature2String();
  39. String getTemperature3String();
  40. };
  41. #endif