Gesture and Proximity Sensor
The APDS9960 sensor on the Inkplate 4 TEMPERA enables gesture recognition, proximity sensing, ambient light measurement, and basic RGB color detection. It’s perfect for swipe-based user interface interaction, detecting nearby motion, or adapting the display based on room lighting.
Initialization and Configuration
Before using the sensor, power it on and initialize it:
inkplate.wakePeripheral(INKPLATE_APDS9960);
if (!inkplate.apds9960.init()) {
inkplate.setCursor(50, 50);
inkplate.print("Can't init APDS!");
inkplate.display();
esp_deep_sleep_start();
}
inkplate.apds9960.init()
Initializes the APDS9960 sensor with default configuration.
Returns value: Returns true if successful, false if initialization fails.
Then, enable the features you need:
inkplate.apds9960.enableProximitySensor(false);
inkplate.apds9960.setProximityGain(1);
inkplate.apds9960.enableGestureSensor();
inkplate.apds9960.setGestureGain(0);
inkplate.apds9960.enableLightSensor(false);
inkplate.apds9960.enableProximitySensor()
Enables the proximity sensing feature.
Returns value: Returns true on success.
Function parameters:
| Type | Name | Description |
|---|---|---|
bool | interrupts | Set true to use interrupts, false for polling. |
inkplate.apds9960.setProximityGain()
Sets the gain for proximity detection.
Returns value: None
Function parameters:
| Type | Name | Description |
|---|---|---|
uint8_t | gain | Gain value (0–3) |
inkplate.apds9960.enableGestureSensor()
Enables gesture sensing.
Returns value: Returns true if successful.
inkplate.apds9960.setGestureGain()
Sets the sensitivity of gesture detection.
Returns value: None
Function parameters:
| Type | Name | Description |
|---|---|---|
uint8_t | gain | Gain value (0–3) |
inkplate.apds9960.enableLightSensor()
Enables the ambient and RGB light sensing.
Returns value: Returns true on success.
Function parameters:
| Type | Name | Description |
|---|---|---|
bool | interrupts | Set true to enable interrupt mode. |
Gesture Detection
if (inkplate.apds9960.isGestureAvailable()) {
int gesture = inkplate.apds9960.readGesture();
switch (gesture) {
case DIR_UP: inkplate.print("Up"); break;
case DIR_DOWN: inkplate.print("Down"); break;
case DIR_LEFT: inkplate.print("Left"); break;
case DIR_RIGHT: inkplate.print("Right"); break;
default: break;
}
inkplate.partialUpdate();
}
inkplate.apds9960.isGestureAvailable()
Checks if a gesture has been detected and is ready to read.
Returns value: Returns true if gesture data is available.
inkplate.apds9960.readGesture()
Reads and returns the last detected gesture.
Returns value: Returns a DIR_* constant representing the gesture, or -1 on failure.
Proximity Reading
uint8_t proximity;
inkplate.apds9960.readProximity(proximity);
inkplate.print(proximity);
inkplate.apds9960.readProximity()
Reads the proximity value from the sensor.
Returns value: Returns true if successful.
Function parameters:
| Type | Name | Description |
|---|---|---|
uint8_t& | val | Variable to store the proximity value (0–255). |
Color Reading (RGB)
uint16_t red, green, blue;
inkplate.apds9960.readRedLight(red);
inkplate.apds9960.readGreenLight(green);
inkplate.apds9960.readBlueLight(blue);
inkplate.printf("Red: %d Green: %d Blue: %d", red, green, blue);
inkplate.apds9960.readRedLight()
Reads red light intensity.
Returns value: Returns true if successful.
Function parameters:
| Type | Name | Description |
|---|---|---|
uint16_t& | val | Red light value. |
inkplate.apds9960.readGreenLight()
Reads green light intensity.
Returns value: Returns true if successful.
Function parameters:
| Type | Name | Description |
|---|---|---|
uint16_t& | val | Green light value. |
inkplate.apds9960.readBlueLight()
Reads blue light intensity.
Returns value: Returns true if successful.
Function parameters:
| Type | Name | Description |
|---|---|---|
uint16_t& | val | Blue light value. |
Ambient Light
uint16_t ambient;
inkplate.apds9960.readAmbientLight(ambient);
inkplate.print(ambient);
inkplate.apds9960.readAmbientLight()
Reads overall ambient light level.
Returns value: Returns true if successful.
Function parameters:
| Type | Name | Description |
|---|---|---|
uint16_t& | val | Ambient light value. |
Gesture Types
| Gesture | Enum Value | Description |
|---|---|---|
| None | DIR_NONE | No gesture detected |
| Left | DIR_LEFT | Right to left |
| Right | DIR_RIGHT | Left to right |
| Up | DIR_UP | Bottom to top |
| Down | DIR_DOWN | Top to bottom |
| Near | DIR_NEAR | Object approaching |
| Far | DIR_FAR | Object moving away |
Example Sketch
The following full example demonstrates how to use all APDS9960 sensor features, including:
- Gesture recognition
- Proximity
- RGB light levels
- Ambient light
Inkplate4TEMPERA_APDS9960.ino
Full Arduino example on how to use the APDS9960 sensor.