Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/***************************************************************************
This is a library for the APDS9960 digital proximity, ambient light, RGB, and gesture sensor
This sketch puts the sensor in gesture mode and decodes gestures.
To use this, first put your hand close to the sensor to enable gesture mode.
Then move your hand about 6" from the sensor in the up -> down, down -> up,
left -> right, or right -> left direction.
Designed specifically to work with the Adafruit APDS9960 breakout
----> http://www.adafruit.com/products/3595
These sensors use I2C to communicate. The device's I2C address is 0x39
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
Written by Dean Miller for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************************************/
#include "Adafruit_APDS9960.h"
#include <Keyboard.h>
Adafruit_APDS9960 apds;
#define INT_PIN 4
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(115200);
if(!apds.begin()){
Serial.println("failed to initialize device! Please check your wiring.");
}
else Serial.println("Device initialized!");
//gesture mode will be entered once proximity mode senses something close
apds.enableProximity(true);
apds.enableGesture(true);
Keyboard.begin();
}
// the loop function runs over and over again forever
void loop() {
// read a gesture from the device
// see list of all keys here: https://www.arduino.cc/en/Reference/KeyboardModifiers
uint8_t gesture = apds.readGesture();
if(gesture == APDS9960_DOWN){
Keyboard.press(KEY_ESC);
delay(100);
Keyboard.releaseAll();
Serial.println("DOWN");
}
if(gesture == APDS9960_UP){
Keyboard.press(KEY_F11);
delay(100);
Keyboard.releaseAll();
Serial.println("UP");
}
if(gesture == APDS9960_LEFT){
Keyboard.press(KEY_LEFT_ARROW);
delay(100);
Keyboard.releaseAll();
Serial.println("LEFT");
}
if(gesture == APDS9960_RIGHT){
Keyboard.press(KEY_RIGHT_ARROW);
delay(100);
Keyboard.releaseAll();
Serial.println("RIGHT");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment