![](/media/cache/profiles/5f14615696649541a025d3d0f8e0447f.jpg.50x50_q85.jpg)
ワークショップ用に公開しているものです。
Fork of Arch_Analog_Thermistor_Blinker by
main.cpp@8:58795209d9c2, 2015-11-14 (annotated)
- Committer:
- jksoft
- Date:
- Sat Nov 14 06:42:28 2015 +0000
- Revision:
- 8:58795209d9c2
- Parent:
- 7:5c2ade6745ae
- Child:
- 9:5a7dca00d87b
????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
viswesr | 0:ed40790a022a | 1 | #include "mbed.h" |
jksoft | 8:58795209d9c2 | 2 | #include "SoftSerial.h" |
viswesr | 0:ed40790a022a | 3 | |
jksoft | 8:58795209d9c2 | 4 | AnalogIn thermistor(dp13); /* Temperature sensor connected to Analog Grove connector */ |
viswesr | 5:d035275d4c21 | 5 | |
jksoft | 8:58795209d9c2 | 6 | SoftSerial pc(dp10,dp11); |
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 |