Junichi Katsu
/
Analog_Temp_Sensor
ワークショップ用に公開しているものです。
Fork of Arch_Analog_Thermistor_Blinker by
main.cpp@9:5a7dca00d87b, 2016-02-27 (annotated)
- Committer:
- jksoft
- Date:
- Sat Feb 27 05:38:49 2016 +0000
- Revision:
- 9:5a7dca00d87b
- Parent:
- 8:58795209d9c2
????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
viswesr | 0:ed40790a022a | 1 | #include "mbed.h" |
jksoft | 9:5a7dca00d87b | 2 | #include "SoftSerialSendOnry.h" |
viswesr | 0:ed40790a022a | 3 | |
jksoft | 8:58795209d9c2 | 4 | AnalogIn thermistor(dp13); /* Temperature sensor connected to Analog Grove connector */ |
viswesr | 5:d035275d4c21 | 5 | |
jksoft | 9:5a7dca00d87b | 6 | SoftSerialSendOnry pc(dp10); // tx |
viswesr | 0:ed40790a022a | 7 | |
viswesr | 0:ed40790a022a | 8 | int main() |
viswesr | 0:ed40790a022a | 9 | { |
viswesr | 5:d035275d4c21 | 10 | unsigned int a, beta = 3975, units, tens; |
viswesr | 5:d035275d4c21 | 11 | float temperature, resistance; |
viswesr | 5:d035275d4c21 | 12 | |
viswesr | 0:ed40790a022a | 13 | while(1) { |
viswesr | 5:d035275d4c21 | 14 | a = thermistor.read_u16(); /* Read analog value */ |
viswesr | 5:d035275d4c21 | 15 | |
viswesr | 5:d035275d4c21 | 16 | /* Calculate the resistance of the thermistor from analog votage read. */ |
viswesr | 6:914bd412ceda | 17 | resistance= (float) 10000.0 * ((65536.0 / a) - 1.0); |
viswesr | 5:d035275d4c21 | 18 | |
viswesr | 5:d035275d4c21 | 19 | /* Convert the resistance to temperature using Steinhart's Hart equation */ |
yihui | 7:5c2ade6745ae | 20 | temperature=(1/((log(resistance/10000.0)/beta) + (1.0/298.15)))-273.15; |
viswesr | 5:d035275d4c21 | 21 | |
jksoft | 8:58795209d9c2 | 22 | pc.printf("temp=%f\r\n",temperature); |
viswesr | 5:d035275d4c21 | 23 | |
viswesr | 5:d035275d4c21 | 24 | wait(0.5); |
viswesr | 0:ed40790a022a | 25 | } |
viswesr | 0:ed40790a022a | 26 | } |
viswesr | 5:d035275d4c21 | 27 |