-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathperson_sensor_arduino.ino
52 lines (47 loc) · 1.44 KB
/
person_sensor_arduino.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
#include <Wire.h>
#include "person_sensor.h"
// How long to wait between reading the sensor. The sensor can be read as
// frequently as you like, but the results only change at about 5FPS, so
// waiting for 200ms is reasonable.
const int32_t SAMPLE_DELAY_MS = 200;
void setup() {
// You need to make sure you call Wire.begin() in setup, or the I2C access
// below will fail.
Wire.begin();
Serial.begin(9600);
}
void loop() {
person_sensor_results_t results = {};
// Perform a read action on the I2C address of the sensor to get the
// current face information detected.
if (!person_sensor_read(&results)) {
Serial.println("No person sensor results found on the i2c bus");
delay(SAMPLE_DELAY_MS);
return;
}
Serial.println("********");
Serial.print(results.num_faces);
Serial.println(" faces found");
for (int i = 0; i < results.num_faces; ++i) {
const person_sensor_face_t* face = &results.faces[i];
Serial.print("Face #");
Serial.print(i);
Serial.print(": ");
Serial.print(face->box_confidence);
Serial.print(" confidence, (");
Serial.print(face->box_left);
Serial.print(", ");
Serial.print(face->box_top);
Serial.print("), (");
Serial.print(face->box_right);
Serial.print(", ");
Serial.print(face->box_bottom);
Serial.print("), ");
if (face->is_facing) {
Serial.println("facing");
} else {
Serial.println("not facing");
}
}
delay(SAMPLE_DELAY_MS);
}