![](/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@2:6b7bb0e0949a, 2015-07-25 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sat Jul 25 13:14:07 2015 +0000
- Revision:
- 2:6b7bb0e0949a
- Parent:
- 1:649b6f2b8f38
- Child:
- 4:16a9eda5ef78
3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:563b65e407e1 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:563b65e407e1 | 2 | // Dual ADT7310's using SPI interface |
MikamiUitOpen | 0:563b65e407e1 | 3 | // このプログラムは printf() 文でマルチバイト文字“℃”を使って |
MikamiUitOpen | 0:563b65e407e1 | 4 | // いるので,コンパイル時に警告が出る |
MikamiUitOpen | 0:563b65e407e1 | 5 | // |
MikamiUitOpen | 2:6b7bb0e0949a | 6 | // 2015/07/25, Copyright (c) 2015 MIKAMI, Naoki |
MikamiUitOpen | 0:563b65e407e1 | 7 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:563b65e407e1 | 8 | |
MikamiUitOpen | 0:563b65e407e1 | 9 | #define ADT7310_DEBUG // デバッグの場合 |
MikamiUitOpen | 0:563b65e407e1 | 10 | #define USING_AQM1602 // LCD 表示装置を使う場合 |
MikamiUitOpen | 0:563b65e407e1 | 11 | |
MikamiUitOpen | 0:563b65e407e1 | 12 | #ifdef USING_AQM1602 |
MikamiUitOpen | 0:563b65e407e1 | 13 | #include "AQM1602.hpp" |
MikamiUitOpen | 0:563b65e407e1 | 14 | #endif |
MikamiUitOpen | 0:563b65e407e1 | 15 | |
MikamiUitOpen | 0:563b65e407e1 | 16 | #include "ADT7310.hpp" |
MikamiUitOpen | 0:563b65e407e1 | 17 | using namespace Mikami; |
MikamiUitOpen | 0:563b65e407e1 | 18 | |
MikamiUitOpen | 0:563b65e407e1 | 19 | #ifdef USING_AQM1602 |
MikamiUitOpen | 0:563b65e407e1 | 20 | Aqm1602 lcd_; // using default port |
MikamiUitOpen | 0:563b65e407e1 | 21 | #endif |
MikamiUitOpen | 0:563b65e407e1 | 22 | |
MikamiUitOpen | 0:563b65e407e1 | 23 | // Declarations of the objects for ADT7310 |
MikamiUitOpen | 0:563b65e407e1 | 24 | ADT7310 sensor1(D10); // Slave select for the sensor: D10 |
MikamiUitOpen | 0:563b65e407e1 | 25 | ADT7310 sensor2(D9); // Slave select for the sensor: D9 |
MikamiUitOpen | 0:563b65e407e1 | 26 | |
MikamiUitOpen | 0:563b65e407e1 | 27 | int main() |
MikamiUitOpen | 0:563b65e407e1 | 28 | { |
MikamiUitOpen | 0:563b65e407e1 | 29 | printf("\r\nStart dual ADT7310s\r\n"); |
MikamiUitOpen | 0:563b65e407e1 | 30 | #ifdef USING_AQM1602 |
MikamiUitOpen | 1:649b6f2b8f38 | 31 | bool on = true; |
MikamiUitOpen | 0:563b65e407e1 | 32 | lcd_.WriteStringXY("Dual ADT7310s", 0, 0); |
MikamiUitOpen | 0:563b65e407e1 | 33 | #endif |
MikamiUitOpen | 0:563b65e407e1 | 34 | /* |
MikamiUitOpen | 0:563b65e407e1 | 35 | sensor1.SetResolution16(); // Set 13-bit resolution mode |
MikamiUitOpen | 0:563b65e407e1 | 36 | sensor2.SetResolution16(true); // Set 16-bit resolution mode |
MikamiUitOpen | 0:563b65e407e1 | 37 | */ |
MikamiUitOpen | 0:563b65e407e1 | 38 | #ifdef ADT7310_DEBUG |
MikamiUitOpen | 0:563b65e407e1 | 39 | uint8_t v1 = sensor1.GetConfigReg(); |
MikamiUitOpen | 0:563b65e407e1 | 40 | uint8_t v2 = sensor2.GetConfigReg(); |
MikamiUitOpen | 0:563b65e407e1 | 41 | printf("v1: 0x%02x, v2: 0x%02x\r\n", v1, v2); |
MikamiUitOpen | 0:563b65e407e1 | 42 | #endif |
MikamiUitOpen | 0:563b65e407e1 | 43 | |
MikamiUitOpen | 0:563b65e407e1 | 44 | while (true) |
MikamiUitOpen | 0:563b65e407e1 | 45 | { |
MikamiUitOpen | 0:563b65e407e1 | 46 | float tempr1 = sensor1.Read(); |
MikamiUitOpen | 0:563b65e407e1 | 47 | float tempr2 = sensor2.Read(); |
MikamiUitOpen | 0:563b65e407e1 | 48 | printf("Sensor1: %5.1f [℃], Sensor2: %5.1f [℃]\r\n", |
MikamiUitOpen | 0:563b65e407e1 | 49 | tempr1, tempr2); |
MikamiUitOpen | 0:563b65e407e1 | 50 | |
MikamiUitOpen | 0:563b65e407e1 | 51 | #ifdef USING_AQM1602 |
MikamiUitOpen | 0:563b65e407e1 | 52 | char str[17]; |
MikamiUitOpen | 0:563b65e407e1 | 53 | sprintf(str, "%5.1f, %5.1f ", tempr1, tempr2); |
MikamiUitOpen | 0:563b65e407e1 | 54 | string s1 = (string)str + (char)0xDF + "C"; |
MikamiUitOpen | 0:563b65e407e1 | 55 | lcd_.WriteStringXY(s1, 0, 1); |
MikamiUitOpen | 1:649b6f2b8f38 | 56 | if (on) lcd_.WriteStringXY(".", 15, 0); |
MikamiUitOpen | 1:649b6f2b8f38 | 57 | else lcd_.WriteStringXY(" ", 15, 0); |
MikamiUitOpen | 1:649b6f2b8f38 | 58 | on = !on; |
MikamiUitOpen | 0:563b65e407e1 | 59 | #endif |
MikamiUitOpen | 0:563b65e407e1 | 60 | wait(1); |
MikamiUitOpen | 0:563b65e407e1 | 61 | } |
MikamiUitOpen | 0:563b65e407e1 | 62 | } |