-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm_TVOC.h
57 lines (42 loc) · 1015 Bytes
/
m_TVOC.h
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
55
56
57
#include <Arduino.h>
#include <SoftI2C.h>
#include "DFRobot_SGP40.h"
// TVOC指数
// 型号:sgp_40
// 接口:VCC->VCC(5V)、GND->GND、SDA->D6、SCL->D7、WAK->GND
// 协议:I2C(软)
// 地址:0x5A
#define _Pin_TVOC_SDA 6
#define _Pin_TVOC_SCL 7
#define _Address_TVOC 0x59
namespace Module {
SoftI2C SoftWire = SoftI2C(_Pin_TVOC_SDA, _Pin_TVOC_SCL); //sda, scl
DFRobot_SGP40 _m_sgp_40(&SoftWire);
struct _TVOC {
void init() {
// 预热10秒
_m_sgp_40.begin(10000);
}
bool isWarmUp = false;
void warmUp() {
if (!isWarmUp) {
isWarmUp = _m_sgp_40.warmUp();
}
}
void adjust(float temp, float hum) {
_m_sgp_40.setRhT(hum, temp);
}
int lastValue = 0;
int getValue() {
int value = isWarmUp ? _m_sgp_40.getVoclndex() : 0;
// 容错交给网页处理,这里只保证在量程之内
if (value < 0 || value > 1000) {
value = lastValue;
} else {
lastValue = value;
}
return value;
}
char unit[6] = "index";
} TVOC;
}