Junichi Katsu
/
Analog_Temp_Sensor
ワークショップ用に公開しているものです。
Fork of Arch_Analog_Thermistor_Blinker by
main.cpp
- Committer:
- jksoft
- Date:
- 2016-02-27
- Revision:
- 9:5a7dca00d87b
- Parent:
- 8:58795209d9c2
File content as of revision 9:5a7dca00d87b:
#include "mbed.h" #include "SoftSerialSendOnry.h" AnalogIn thermistor(dp13); /* Temperature sensor connected to Analog Grove connector */ SoftSerialSendOnry pc(dp10); // tx int main() { unsigned int a, beta = 3975, units, tens; float temperature, resistance; while(1) { a = thermistor.read_u16(); /* Read analog value */ /* Calculate the resistance of the thermistor from analog votage read. */ resistance= (float) 10000.0 * ((65536.0 / a) - 1.0); /* Convert the resistance to temperature using Steinhart's Hart equation */ temperature=(1/((log(resistance/10000.0)/beta) + (1.0/298.15)))-273.15; pc.printf("temp=%f\r\n",temperature); wait(0.5); } }