Skip to main content

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:

TypeNameDescription
boolinterruptsSet true to use interrupts, false for polling.

inkplate.apds9960.setProximityGain()

Sets the gain for proximity detection.

Returns value: None

Function parameters:

TypeNameDescription
uint8_tgainGain 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:

TypeNameDescription
uint8_tgainGain value (0–3)

inkplate.apds9960.enableLightSensor()

Enables the ambient and RGB light sensing.

Returns value: Returns true on success.

Function parameters:

TypeNameDescription
boolinterruptsSet 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:

TypeNameDescription
uint8_t&valVariable 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:

TypeNameDescription
uint16_t&valRed light value.

inkplate.apds9960.readGreenLight()

Reads green light intensity.

Returns value: Returns true if successful.

Function parameters:

TypeNameDescription
uint16_t&valGreen light value.

inkplate.apds9960.readBlueLight()

Reads blue light intensity.

Returns value: Returns true if successful.

Function parameters:

TypeNameDescription
uint16_t&valBlue 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:

TypeNameDescription
uint16_t&valAmbient light value.

Gesture Types

GestureEnum ValueDescription
NoneDIR_NONENo gesture detected
LeftDIR_LEFTRight to left
RightDIR_RIGHTLeft to right
UpDIR_UPBottom to top
DownDIR_DOWNTop to bottom
NearDIR_NEARObject approaching
FarDIR_FARObject 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.