-
Notifications
You must be signed in to change notification settings - Fork 8
Exercise 09: Monitor Gesture Direction from APDS9960
Mohamad Ariffin Zulkifli edited this page Apr 18, 2021
·
1 revision
In this exercise, we will use same APDS9960 from Exercise 8 with different application of sensing gesture direction, the sketch as follows:
Complete Sketch
// include the Adafruit_APDS9960 header file.
#include <Adafruit_APDS9960.h>
// instance of the Adafruit_APDS9960 class named as apds.
Adafruit_APDS9960 apds;
void setup() {
// Initialize the serial communication with baud rate 9600bps.
Serial.begin(9600);
// Initialize APDS9960 sensor and if the connection is not successful,
// print the failed status to the Serial Monitor.
if (!apds.begin()){
Serial.println("Failed to find Hibiscus Sense APDS9960 chip");
}
// enable the proximity mode on APDS9960
apds.enableProximity(true);
// enable the gesture mode on APDS9960
apds.enableGesture(true);
}
void loop() {
// to acquire APDS9960 gesture direction,
// we need to call apds.readGesture() function from apds instance.
uint8_t gesture = apds.readGesture();
if(gesture == APDS9960_DOWN) Serial.println("Gesture Direction: DOWN");
if(gesture == APDS9960_UP) Serial.println("Gesture Direction: UP");
if(gesture == APDS9960_LEFT) Serial.println("Gesture Direction: LEFT");
if(gesture == APDS9960_RIGHT) Serial.println("Gesture Direction: RIGHT");
}
Now, we can upload the complete sketch to ESP32, once done uploading open the Serial Monitor. To try the gesture:
- Activate the proximity by hovering our hands close as possible above the APDS9960.
- Make gesture by hivering our hands into direction of UP, DOWN, RIGHT and LEFT.
We should see the direction on the Serial Monitor, as on the image below: