![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
SPI 接続の温度センサ ADT7310 用のライブラリの使用例. Demo program of the library for temperature sensor ADT7310 connected using SPI interface.
Dependencies: UIT_ADT7310 UIT_AQM1602 mbed
main.cpp
- Committer:
- MikamiUitOpen
- Date:
- 2015-06-28
- Revision:
- 1:649b6f2b8f38
- Parent:
- 0:563b65e407e1
- Child:
- 2:6b7bb0e0949a
File content as of revision 1:649b6f2b8f38:
//-------------------------------------------------------------- // Dual ADT7310's using SPI interface // このプログラムは printf() 文でマルチバイト文字“℃”を使って // いるので,コンパイル時に警告が出る // // 2015/06/28, Copyright (c) 2015 MIKAMI, Naoki //-------------------------------------------------------------- #define ADT7310_DEBUG // デバッグの場合 #define USING_AQM1602 // LCD 表示装置を使う場合 #ifdef USING_AQM1602 #include "AQM1602.hpp" #endif #include "ADT7310.hpp" using namespace Mikami; #ifdef USING_AQM1602 Aqm1602 lcd_; // using default port #endif // Declarations of the objects for ADT7310 ADT7310 sensor1(D10); // Slave select for the sensor: D10 ADT7310 sensor2(D9); // Slave select for the sensor: D9 int main() { printf("\r\nStart dual ADT7310s\r\n"); #ifdef USING_AQM1602 bool on = true; lcd_.WriteStringXY("Dual ADT7310s", 0, 0); #endif /* sensor1.SetResolution16(); // Set 13-bit resolution mode sensor2.SetResolution16(true); // Set 16-bit resolution mode */ #ifdef ADT7310_DEBUG uint8_t v1 = sensor1.GetConfigReg(); uint8_t v2 = sensor2.GetConfigReg(); printf("v1: 0x%02x, v2: 0x%02x\r\n", v1, v2); #endif while (true) { float tempr1 = sensor1.Read(); float tempr2 = sensor2.Read(); printf("Sensor1: %5.1f [℃], Sensor2: %5.1f [℃]\r\n", tempr1, tempr2); #ifdef USING_AQM1602 char str[17]; sprintf(str, "%5.1f, %5.1f ", tempr1, tempr2); string s1 = (string)str + (char)0xDF + "C"; lcd_.WriteStringXY(s1, 0, 1); if (on) lcd_.WriteStringXY(".", 15, 0); else lcd_.WriteStringXY(" ", 15, 0); on = !on; #endif wait(1); } }