ワークショップ用に公開しているものです。

Dependencies:   mbed

Fork of Arch_Analog_Thermistor_Blinker by Yihui Xiong

main.cpp

Committer:
jksoft
Date:
2015-11-14
Revision:
8:58795209d9c2
Parent:
7:5c2ade6745ae
Child:
9:5a7dca00d87b

File content as of revision 8:58795209d9c2:

#include "mbed.h"
#include "SoftSerial.h"

AnalogIn thermistor(dp13);   /* Temperature sensor connected to Analog Grove connector */

SoftSerial pc(dp10,dp11);

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);
    }
}