#ifndef TMP36_ANALOG_H #define TMP36_ANALOG_H #include "tmp36.h" #include "hal.h" /* * TMP36 -- Real hardware implementation (analog read). * * The TMP36 outputs a voltage proportional to temperature: * - 10 mV per degree Celsius * - 500 mV offset at 0 C (so 750 mV = 25 C) * - Range: -40 C to +125 C * * Wiring: * TMP36 pin 1 (left) -> 5V (or 3.3V) * TMP36 pin 2 (middle) -> Analog input (A0 by default) * TMP36 pin 3 (right) -> GND * * If your board runs at 3.3V, pass 3.3f as ref_voltage. */ class Tmp36Analog : public TempSensor { public: /// Create a TMP36 sensor on the given analog pin. /// ref_voltage: board reference voltage (5.0 for Uno, 3.3 for Due/ESP). Tmp36Analog(Hal* hal, uint8_t pin, float ref_voltage = 5.0f) : hal_(hal) , pin_(pin) , ref_mv_(ref_voltage * 1000.0f) {} float readCelsius() override { int raw = hal_->analogRead(pin_); float mv = (float)raw * ref_mv_ / 1024.0f; return (mv - 500.0f) / 10.0f; } int readRaw() override { return hal_->analogRead(pin_); } private: Hal* hal_; uint8_t pin_; float ref_mv_; }; #endif // TMP36_ANALOG_H