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-10-28
Revision:
5:8da999cd764a
Parent:
4:16a9eda5ef78

File content as of revision 5:8da999cd764a:

//--------------------------------------------------------------
//  ADT7310 using SPI interface
//
//      mbed revision: 154
//
//  2017/10/28, Copyright (c) 2017 MIKAMI, Naoki
//--------------------------------------------------------------

#pragma diag_suppress 870   // マルチバイト文字使用の警告を抑制
#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

// Declaration of the object for ADT7310
ADT7310 sensor1(D10);   // Slave select for the sensor: D10

int main()
{
    printf("\r\nStart ADT7310\r\n");
#ifdef USING_AQM1602
    bool on = true;
    lcd_.WriteStringXY("ADT7310", 0, 0);
#endif 

#ifdef ADT7310_DEBUG
// print out content of configuration registers
    uint8_t reg = sensor1.GetConfigReg();
    printf("Config reg.: 0x%02x\r\n", reg);
#endif

    while (true)
    {
        float tempr1 = sensor1.Read();   
        printf("%5.1f [℃]\r\n", tempr1);
        
#ifdef USING_AQM1602
        lcd_.ClearLine(1);
        lcd_.WriteValueXY("%5.1f \xDF""C", tempr1, 0, 1);

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