Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Condensation_Monitor mbed_HDC1000 BLE_Condensation_Monitor GR-PEACH_TAMORI
HDC1000.cpp
00001 //********************** 00002 // HDC1000.cpp for mbed 00003 // 00004 // HDC1000 hdc1000(P0_5,P0_4); 00005 // or 00006 // I2C i2c(P0_5,P0_4); 00007 // HDC1000 hdc1000(i2c); 00008 // 00009 // (C)Copyright 2015 All rights reserved by Y.Onodera 00010 // http://einstlab.web.fc2.com 00011 //********************** 00012 00013 #include "mbed.h" 00014 #include "HDC1000.h" 00015 00016 HDC1000::HDC1000 (PinName sda, PinName scl) : _i2c(sda, scl) { 00017 init(); 00018 } 00019 HDC1000::HDC1000 (I2C& p_i2c) : _i2c(p_i2c) { 00020 init(); 00021 } 00022 00023 00024 void HDC1000::get() 00025 { 00026 00027 // Trigger 00028 buf[0] = 0x00; // Pointer 00029 _i2c.write(HDC1000_ADDR, buf, 1); // with stop 00030 00031 // Wait 6.35ms + 6.5ms 00032 wait_ms(20); 00033 00034 // get data 00035 _i2c.read( HDC1000_ADDR, buf, 4); 00036 00037 } 00038 00039 unsigned short HDC1000::humidity() 00040 { 00041 00042 // get hum 00043 get(); 00044 hum.byte.HB=buf[2]; 00045 hum.byte.LB=buf[3]; 00046 return hum.Val; 00047 00048 } 00049 00050 unsigned short HDC1000::temperature() 00051 { 00052 00053 // get temp 00054 get(); 00055 temp.byte.HB=buf[0]; 00056 temp.byte.LB=buf[1]; 00057 return temp.Val; 00058 00059 } 00060 00061 void HDC1000::init() 00062 { 00063 00064 wait_ms(15); 00065 00066 // Set configuration 00067 buf[0] = 0x02; // Pointer 00068 buf[1] = 0x10; // High byte 00069 buf[2] = 0x00; // Low byte 00070 _i2c.write(HDC1000_ADDR, buf, 3); 00071 } 00072 00073 00074
Generated on Sat Jul 16 2022 01:32:43 by
1.7.2