Junichi Katsu
/
Analog_Temp_Sensor
ワークショップ用に公開しているものです。
Fork of Arch_Analog_Thermistor_Blinker by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "SoftSerialSendOnry.h" 00003 00004 AnalogIn thermistor(dp13); /* Temperature sensor connected to Analog Grove connector */ 00005 00006 SoftSerialSendOnry pc(dp10); // tx 00007 00008 int main() 00009 { 00010 unsigned int a, beta = 3975, units, tens; 00011 float temperature, resistance; 00012 00013 while(1) { 00014 a = thermistor.read_u16(); /* Read analog value */ 00015 00016 /* Calculate the resistance of the thermistor from analog votage read. */ 00017 resistance= (float) 10000.0 * ((65536.0 / a) - 1.0); 00018 00019 /* Convert the resistance to temperature using Steinhart's Hart equation */ 00020 temperature=(1/((log(resistance/10000.0)/beta) + (1.0/298.15)))-273.15; 00021 00022 pc.printf("temp=%f\r\n",temperature); 00023 00024 wait(0.5); 00025 } 00026 } 00027
Generated on Thu Jul 21 2022 09:55:24 by 1.7.2