-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathGestureSensor.ino
68 lines (53 loc) · 1.66 KB
/
GestureSensor.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
/*
APDS9960 - Gesture Sensor
This example reads gesture data from the on-board APDS9960 sensor of the
Nano 33 BLE Sense and prints any detected gestures to the Serial Monitor.
Gesture directions are as follows:
- UP: from USB connector towards antenna
- DOWN: from antenna towards USB connector
- LEFT: from analog pins side towards digital pins side
- RIGHT: from digital pins side towards analog pins side
The circuit:
- Arduino Nano 33 BLE Sense
This example code is in the public domain.
*/
#include <Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;
void setup() {
Serial.begin(9600);
while (!Serial);
carrier.noCase();
if (!carrier.begin()) {
Serial.println("Error");
}
// for setGestureSensitivity(..) a value between 1 and 100 is required.
// Higher values makes the gesture recognition more sensible but less accurate
// (a wrong gesture may be detected). Lower values makes the gesture recognition
// more accurate but less sensible (some gestures may be missed).
// Default is 80
//APDS.setGestureSensitivity(80);
Serial.println("Detecting gestures ...");
}
void loop() {
if (carrier.Light.gestureAvailable()) {
// a gesture was detected, read and print to serial monitor
int gesture = APDS.readGesture();
switch (gesture) {
case UP:
Serial.println("Detected UP gesture");
break;
case DOWN:
Serial.println("Detected DOWN gesture");
break;
case LEFT:
Serial.println("Detected LEFT gesture");
break;
case RIGHT:
Serial.println("Detected RIGHT gesture");
break;
default:
// ignore
break;
}
}
}