I2C 接続の温度センサ ADT7410 用のライブラリの使用例. Demo program of the library for temperature sensor ADT7410 connected using I2C interface.
Dependencies: mbed UIT_ADT7410
Diff: main.cpp
- Revision:
- 13:7f89953302c5
- Parent:
- 12:9a71c11c8e92
diff -r 9a71c11c8e92 -r 7f89953302c5 main.cpp --- a/main.cpp Thu Apr 02 02:38:48 2020 +0000 +++ b/main.cpp Thu Apr 16 04:30:15 2020 +0000 @@ -1,48 +1,46 @@ //-------------------------------------------------------------- -// ADT7410 and LCD display using I2C interface -// mbed revision: 172 -// 2020/04/02, Copyright (c) 2020 MIKAMI, Naoki +// ADT7410 クラスの使用例 +// 割込みを使わない場合は "#define USING_INTERRUPT" を +// コメントアウトする +// +// 使用した mbed ライブラリ: Rev.172 +// 使用した Aqm1602 用ライブラリ: Rev.7 +// +// 2020/04/16, Copyright (c) 2020 MIKAMI, Naoki //-------------------------------------------------------------- #pragma diag_suppress 870 // マルチバイト文字使用の警告を抑制 +#define USING_INTERRUPT // 割込みを使わない場合はコメントアウト #include "ADT7410.hpp" using namespace Mikami; -// If you want to display the temperature on AQM1602, -// enable following #define statement -#define USING_AQM1602 +ADT7410 tempr_; // Nucleo-F446RE のデフォルトの I2C ポート使用 -#ifdef USING_AQM1602 -#include "AQM1602.hpp" -Aqm1602 lcd_; // using default I2C port -#endif // #ifdef USING_AQM1602 - -ADT7410 tempr_; // using default I2C port +// 温度の読み込みと表示 +// この関数は割込みサービス・ルーチンとしても使える +void ReadAndPrintF() +{ + float value = tempr_.Read(); // 温度の読み込み + printf("%5.1f [℃]\r\n", value); +} int main() { - printf("\r\nStart ADT7410\r\n"); -#ifdef USING_AQM1602 - bool on = true; - lcd_.WriteStringXY("ADT7410", 0, 0); -#endif // #ifdef USING_AQM1602 + printf("\r\nADT7410 クラスのデモプログラムの開始\r\n"); - // Confirmation of setting - uint8_t cReg = tempr_.GetConfig(); - printf("Mode: 0x%02x\r\n", cReg); - +#ifdef USING_INTERRUPT + printf("割込みサービス・ルーチンで温度を読み込みます\r\n"); + Ticker timer; // タイマ割込み + timer.attach(&ReadAndPrintF, 1); // タイマ割込み間隔: 1 秒 +#else + printf("割込みを使いません\r\n"); +#endif + while (true) { -// float value = tempr_.Read(); // Member function version - float value = tempr_; // Operator version - -#ifdef USING_AQM1602 - lcd_.WriteValueXY("%5.1f \xDF""C", value, 0, 1); - if (on) lcd_.WriteStringXY(".", 15, 0); - else lcd_.WriteStringXY(" ", 15, 0); - on = !on; -#endif // #ifdef USING_AQM1602 - printf("%5.1f [℃]\r\n", value); +#ifndef USING_INTERRUPT // 割込みを使わない場合 + ReadAndPrint(); wait(1); +#endif } } \ No newline at end of file