-
Notifications
You must be signed in to change notification settings - Fork 0
/
aht10.cpp
54 lines (44 loc) · 920 Bytes
/
aht10.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//#include "Arduino.h"
#include "aht10.h"
double aht10th::rhRead()
{
uint32_t rhData;
for(int8_t i = 0; i < 2; i++)
{
rhData |= readByte[1 + i];
rhData = rhData << 4;
}
rhData = (rhData << 4) | (readByte[3] >> 4);
double rh = (double) rhData * 0.000095;
return rh;
}
double aht10th::tempRead()
{
uint32_t tempData = readByte[3] & 0x0F;
for(int8_t i = 0; i < 2; i++)
{
tempData = tempData << 8 | readByte[4 + i];
}
//uint32_t tempData = ((uint32_t) readByte[3] & 0x0F) << 16 | ((uint16_t) readByte[4]) << 8 | readByte[5];
double temp = (double) tempData * 0.000191 - 50;
return temp;
}
void aht10th::reqData()
{
Wire.requestFrom(I2C_ADDR, 6);
for(int i = 0; i < 6; i++)
{
readByte[i] = Wire.read();
}
}
void aht10th::trigMeasure()
{
Wire.beginTransmission(I2C_ADDR);
Wire.write(TRIG_MEASURE);
Wire.endTransmission();
}
void aht10th::begin()
{
Wire.begin();
}
aht10th aht;