-
Notifications
You must be signed in to change notification settings - Fork 1
/
sketch_both_libs.ino
71 lines (59 loc) · 1.89 KB
/
sketch_both_libs.ino
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <Wire.h>
#include <SparkFun_Qwiic_Humidity_AHT20.h>
#include <SparkFun_SGP40_Arduino_Library.h>
#include "ArduinoGraphics.h"
#include "Arduino_LED_Matrix.h"
AHT20 ahtSensor;
SGP40 sgpSensor;
ArduinoLEDMatrix matrix;
void setup() {
Serial.begin(9600);
matrix.begin();
Wire1.begin(); //Join I2C bus
//Check if the AHT20 will acknowledge
if (ahtSensor.begin(Wire1) == false) {
Serial.println("AHT20 not detected. Check connections. Freezing.");
while (1)
;
}
Serial.println("AHT20 acknowledged.");
if (sgpSensor.begin(Wire1) == false) {
Serial.println(F("SGP40 not detected. Check connections. Freezing..."));
while (1)
;
}
Serial.println("SGP40 acknowledged.");
}
void loop() {
//If a new measurement is available
if (ahtSensor.available() == true) {
//Get the new temperature and humidity value
float temperature = ahtSensor.getTemperature();
float humidity = ahtSensor.getHumidity();
int voc = sgpSensor.getVOCindex(humidity, temperature);
//Print the results
Serial.print("Temperature: ");
Serial.print(temperature, 2);
Serial.print(" C\t");
Serial.print("Humidity: ");
Serial.print(humidity, 2);
Serial.print("% RH\t");
Serial.print("VOC Index is: ");
Serial.println(voc);
Serial.println();
// Make it scroll!
matrix.beginDraw();
matrix.stroke(0xFFFFFFFF);
matrix.textScrollSpeed(50);
// add the text
const String text = " Temp: " + String(temperature) + " Humidity: " + String(humidity) + " VOC: " + String(voc) + " ";
matrix.textFont(Font_5x7);
matrix.beginText(0, 1, 0xFFFFFF);
matrix.println(text);
matrix.endText(SCROLL_LEFT);
matrix.endDraw();
}
//The AHT20 can respond with a reading every ~50ms. However, increased read time can cause the IC to heat around 1.0C above ambient.
//The datasheet recommends reading every 2 seconds.
delay(2000);
}