-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathmain.cpp
67 lines (58 loc) · 1.93 KB
/
main.cpp
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
#include <Arduino.h>
#include "SparkFun_APDS9960.h"
SparkFun_APDS9960 apds = SparkFun_APDS9960();
#define CHECK(f, msg) \
ar = f; \
Serial.print(msg); \
Serial.println((ar) ? " OK" : " failed")
const char *gestureName[] = {"Left", "Right", "Up", "Down"};
void setup() {
// Initialize Serial port
Serial.begin(115200);
Serial.println();
Serial.println(F("-----------------------"));
Serial.println(F("APDS-9960 - GestureTest"));
Serial.println(F("-----------------------"));
// Initialize APDS-9960 (configure I2C and initial values)
if (apds.init()) {
Serial.println(F("APDS-9960 initialization complete"));
} else {
Serial.println(F("Something went wrong during APDS-9960 init!"));
}
// Start running the APDS-9960 gesture sensor engine
if (apds.enableGestureSensor(true)) {
Serial.println(F("Gesture sensor is now running"));
} else {
Serial.println(F("Something went wrong during gesture sensor init!"));
}
bool ar;
CHECK(apds.setGestureLEDDrive(2), "gesture LED drive");
CHECK(apds.setGestureIntEnable(0), "int en");
CHECK(apds.setGestureGain(GGAIN_4X), "gesture gain");
CHECK(apds.enableProximitySensor(false), "Prox sensor");
CHECK(apds.setProximityGain(PGAIN_4X), "Prox gain");
// CHECK(apds.setGestureTimeout(3000), "Gesture timeout");
}
void loop() {
Gesture gesture = apds.checkGesture();
switch (gesture) {
case DIR_UP:
case DIR_DOWN:
case DIR_LEFT:
case DIR_RIGHT:
Serial.println(gestureName[gesture - 1]);
break;
case DIR_NEAR:
Serial.println("NEAR");
break;
case DIR_FAR:
Serial.println("FAR");
break;
case DIR_PENDING:
Serial.print("...");
default:
// Don't print, we'll be here a LOT!
// Serial.print("/");
break;
}
}