Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of read_analog by
Diff: main.cpp
- Revision:
- 1:732610676e2e
- Parent:
- 0:140f2dc46122
--- a/main.cpp Wed Jul 11 09:28:45 2018 +0000 +++ b/main.cpp Fri Jul 27 15:31:36 2018 +0000 @@ -1,17 +1,17 @@ #include "mbed.h" -AnalogIn analog_value(dp13); +AnalogIn analog_value(dp13); // dp13ピンをアナログ入力として利用、analog_value変数に割当 int main(void) { - float meas, temp; - printf("\r\nAnalogIn example\r\n"); - while(1) { - meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) - meas = meas * 3300; // Change the value to be in the 0 to 3300 range (mV) - temp = 0.1 * meas - 50; // for TMP36GT9Z - printf("measure = %.0f mV, temp = %.1f C\r\n", meas, temp); - wait(0.2); // 200 ms + float meas, temp; // 浮動小数点(実数)を入れる変数としてmeas, tempを用意 + printf("\r\nAnalogIn example\r\n"); // メッセージの表示 + while(1) { // 「無限に繰り返す」の意味 + meas = analog_value.read(); // dp13 ピンへの電圧入力値(0~3.3V)をA/D変換し、さらに0.0~1.0 の間の数値に変換されたものを取り出し、measに代入 + meas = meas * 3300; // measの値を3300倍することで、元の電圧値に対応する分かりやすい値の範囲に変換 (0~3300mV) + temp = 0.1 * meas - 50; // TMP36GT9Z のデータシートに基づき、電圧値から温度の物理値へと変換し、tempに代入 + printf("measure = %.0f mV, temp = %.1f C\r\n", meas, temp); // 電圧値そのもの(meas)と温度データ(temp)を表示 + wait(0.2); // 200 ms 待つ } }