test program for HDC1000

Dependencies:   HDC1000 mbed

main.cpp

Committer:
Rhyme
Date:
2017-04-17
Revision:
0:655618676da2
Child:
1:03353fe864df

File content as of revision 0:655618676da2:

#include "mbed.h"
#include "MSS.h"
#include "HDC1000.h"

#define HDC1000_I2C_ADDRESS   0x40

HDC1000 *hdc1000 = 0 ;

int main() {
    float temp, hume ;
    uint16_t device_id, manufacture_id ;
    uint16_t utemp, uhume ;
    uint16_t conf = 0 ;
    int mode = 0 ;
    
    hdc1000 = new HDC1000(PIN_SDA, PIN_SCL, PIN_INT0, HDC1000_I2C_ADDRESS) ;
//    hdc1000 = new HDC1000(PIN_SDA, PIN_SCL, HDC1000_I2C_ADDRESS) ;
    hdc1000->reset() ;
    wait(2) ;
    conf = 0x0000 ;
    hdc1000->setConfig(conf) ;
    conf = 0x1000 ;
    hdc1000->setConfig(conf) ;
    conf = hdc1000->getConfig() ;
    printf("Config = 0x%04X\n", conf) ;
    
    device_id = hdc1000->getDeviceID() ;
    printf("Device ID = 0x%04X\n", device_id) ;
    manufacture_id = hdc1000->getManufactureID() ;
    printf("Manufacture ID = 0x%04X\n", manufacture_id) ;
    printf("=== test HDC1000 for %s (%s) ===\n", BOARD_NAME, __DATE__) ;
    mode = 0 ;
    printf("mode = %d\n", mode) ;
    hdc1000->setMode(mode) ;

    while(1) {
        printf("mode = %d\n", mode) ;
        hdc1000->setMode(mode) ;
        wait(1) ;
        if (mode == 1) {
            hdc1000->readData(&temp, &hume) ;
            printf("Temperature:%.2f C  Humidity:%.2f %%\n",temp, hume) ;
        } else {
            temp = hdc1000->readTemperature() ;
            hume = hdc1000->readHumidity() ;
            
            printf("Temperature: %.2f ", temp) ;
            printf("Humidity: %.2f%%\n", hume) ;
        }
        wait(2) ;
        mode = (mode == 0) ? 1 : 0 ;
    }
}