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:
2017-06-03
Revision:
4:16a9eda5ef78
Parent:
2:6b7bb0e0949a
Child:
5:8da999cd764a

File content as of revision 4:16a9eda5ef78:

//--------------------------------------------------------------
//  Dual ADT7310's using SPI interface
//      このプログラムは printf() 文でマルチバイト文字“℃”を
//      使っているので,コンパイル時に警告が出る
//
//      このプログラムは温度センサを2個使うということを前提に
//      しているプログラムなので,温度センサが1個でも動くが,
//      その場合の対応は特に行っていない
//
//  2017/06/03, Copyright (c) 2017 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
// print out content of configuration registers
    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
        lcd_.ClearLine(1);
        lcd_.WriteValueXY("%5.1f, ", tempr1, 0, 1);
        lcd_.WriteValue("%5.1f \xDF\x43", tempr2);

        if (on) lcd_.WriteStringXY(".", 15, 0);
        else    lcd_.WriteStringXY(" ", 15, 0);
        on = !on;
#endif
        wait(1);
    }
}