![](/media/cache/profiles/5f14615696649541a025d3d0f8e0447f.jpg.50x50_q85.jpg)
ワークショップ用に公開しているものです。
Fork of Arch_Analog_Thermistor_Blinker by
main.cpp@7:5c2ade6745ae, 2014-08-20 (annotated)
- Committer:
- yihui
- Date:
- Wed Aug 20 07:17:31 2014 +0000
- Revision:
- 7:5c2ade6745ae
- Parent:
- 6:914bd412ceda
- Child:
- 8:58795209d9c2
fix the equation and change the analog pin
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
viswesr | 0:ed40790a022a | 1 | #include "mbed.h" |
viswesr | 0:ed40790a022a | 2 | |
yihui | 7:5c2ade6745ae | 3 | AnalogIn thermistor(A1); /* Temperature sensor connected to Analog Grove connector */ |
viswesr | 5:d035275d4c21 | 4 | |
viswesr | 5:d035275d4c21 | 5 | DigitalOut tensplaceLED(LED4); /* This led blinks as per tens place of temperature value(in deg C) */ |
viswesr | 5:d035275d4c21 | 6 | DigitalOut unitsplaceLED(LED1); /* This led blinks as per units place of temperature value(in deg C) */ |
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 | |
viswesr | 5:d035275d4c21 | 22 | units = (int) temperature % 10; |
viswesr | 5:d035275d4c21 | 23 | tens = (int) temperature / 10; |
viswesr | 5:d035275d4c21 | 24 | |
viswesr | 5:d035275d4c21 | 25 | |
viswesr | 5:d035275d4c21 | 26 | for(int i=0; i< tens; i++) |
viswesr | 5:d035275d4c21 | 27 | { |
viswesr | 5:d035275d4c21 | 28 | tensplaceLED = 1; |
viswesr | 5:d035275d4c21 | 29 | wait(.200); |
viswesr | 5:d035275d4c21 | 30 | tensplaceLED = 0; |
viswesr | 5:d035275d4c21 | 31 | wait(.200); |
viswesr | 4:ba523da0d68a | 32 | } |
viswesr | 5:d035275d4c21 | 33 | |
viswesr | 5:d035275d4c21 | 34 | for(int i=0; i< units; i++) |
viswesr | 5:d035275d4c21 | 35 | { |
viswesr | 5:d035275d4c21 | 36 | unitsplaceLED = 1; |
viswesr | 5:d035275d4c21 | 37 | wait(.200); |
viswesr | 5:d035275d4c21 | 38 | unitsplaceLED = 0; |
viswesr | 5:d035275d4c21 | 39 | wait(.200); |
viswesr | 5:d035275d4c21 | 40 | } |
viswesr | 5:d035275d4c21 | 41 | |
viswesr | 5:d035275d4c21 | 42 | wait(0.5); |
viswesr | 0:ed40790a022a | 43 | } |
viswesr | 0:ed40790a022a | 44 | } |
viswesr | 5:d035275d4c21 | 45 |