-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccs811.cpp
More file actions
38 lines (32 loc) · 897 Bytes
/
ccs811.cpp
File metadata and controls
38 lines (32 loc) · 897 Bytes
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
#include "ccs811.h"
Adafruit_CCS811 ccs811;
// Global variables to hold CCS811 data
extern float co2;
extern float tvoc;
void setupCCS811() {
if (!ccs811.begin()) {
Serial.println("Failed to start CCS811 sensor! Please check your wiring.");
while (1); // Halt execution if sensor is not found
}
// Wait for the sensor to be ready
while (!ccs811.available());
}
void readCCS811Data() {
if (ccs811.available()) {
if (!ccs811.readData()) {
co2 = ccs811.geteCO2();
tvoc = ccs811.getTVOC();
// Print CCS811 data
// Serial.print("CO2: ");
// Serial.print(co2);
// Serial.print(" ppm, TVOC: ");
// Serial.print(tvoc);
// Serial.println(" ppb");
// EndPrint CCS811 data
} else {
Serial.println("Error reading data from CCS811 sensor!");
}
} else {
Serial.println("CCS811 sensor not available");
}
}