-
Notifications
You must be signed in to change notification settings - Fork 4
/
04_06_fast_read_of_Si7021.c
55 lines (48 loc) · 1.03 KB
/
04_06_fast_read_of_Si7021.c
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
#include "Adafruit_Si7021.h"
Adafruit_Si7021 sensor = Adafruit_Si7021();
void setup() {
Serial.begin(115200);
// wait for serial port to open
while (!Serial) {
delay(10);
}
Serial.println("Si7021 test!");
if (!sensor.begin()) {
Serial.println("Did not find Si7021 sensor!");
while (true);
}
}
void loop() {
float hum[15], temp[15];
long t[15];
int i;
// measure humidity
for (i = 0; i < 15; i++) {
hum[i] = sensor.readHumidity();
t[i] = micros();
}
// print
for (i = 1; i < 15; i++) {
Serial.print(t[i]);
Serial.print("\t");
Serial.print(t[i] - t[i - 1]);
Serial.print("\t");
Serial.println(hum[i]);
}
Serial.println();
// measure temperature
for (i = 0; i < 15; i++) {
temp[i] = sensor.readTemperature();
t[i] = micros();
}
// print results
for (i = 1; i < 15; i++) {
Serial.print(t[i]);
Serial.print("\t");
Serial.print(t[i] - t[i - 1]);
Serial.print("\t");
Serial.println(temp[i]);
}
Serial.println("----------");
delay(2000);
}