Example: 50-Arduino-Boards/Nano-33-BLE-Sense/51-Sensors/apds9960/gesture.py
from time import sleep_ms
from machine import Pin, I2C
from apds9960.const import *
from apds9960 import uAPDS9960 as APDS9960
bus = I2C(1, scl=Pin(15), sda=Pin(14))
apds = APDS9960(bus)
dirs = {
APDS9960_DIR_NONE: "none",
APDS9960_DIR_LEFT: "left",
APDS9960_DIR_RIGHT: "right",
APDS9960_DIR_UP: "up",
APDS9960_DIR_DOWN: "down",
APDS9960_DIR_NEAR: "near",
APDS9960_DIR_FAR: "far",
}
apds.setProximityIntLowThreshold(50)
print("Gesture Test")
print("============")
apds.enableGestureSensor()
while True:
sleep_ms(500)
if apds.isGestureAvailable():
motion = apds.readGesture()
print("Gesture={}".format(dirs.get(motion, "unknown")))