A library for the combined proximity, ambient light, RGB color and gesture sensor Avago APDS9960. Tested with corresponding breakout board from SparkFun.
Small test program that briefly shows the usage of the library (only gesture detection). It uses my SFE_MicroOLED Library for result output on a 64 x 48 pixel small 0.66" OLED screen. But it should be easy to change the output to the Serial interface. The platform used was a LPCXpresso11U68:
gesture detection Test-Program
#include "mbed.h" #include "SparkFun_APDS9960.h" #include "SFE_MicroOLED.h" // Constants // Global Variables and forward declarations InterruptIn apds_int(P1_24); SPI my_spi(P0_9, P0_8, P1_29); MicroOLED uView(my_spi, P2_3, P1_28, P1_25); I2C my_i2c(P0_5, P0_4); SparkFun_APDS9960 apds = SparkFun_APDS9960(my_i2c); volatile int isr_flag = 0; void interruptRoutine(); void handleGesture(); void drawArrowUp(); void drawArrowDown(); void drawArrowLeft(); void drawArrowRight(); void drawCircle(); void drawX(); int main() { // Initialize MicroView uView.init(0, 8000000); uView.clear(PAGE); // Initialize interrupt service routine apds_int.mode(PullUp); apds_int.fall(&interruptRoutine); apds_int.disable_irq(); uView.setFontType(0); wait_ms(500); // Initialize APDS-9960 (configure I2C and initial values) if ( apds.init(400000) ) { uView.puts("INIT OK!\n"); } else { uView.puts("I-ERROR!\n"); } // Start running the gesture sensor engine (with interrupts) if ( apds.enableGestureSensor(true) ) { uView.puts("Gest OK!"); } else { uView.puts("G-ERROR!"); } uView.display(); // Wait for initialization and calibration to finish wait_ms(2000); uView.clear(PAGE); // Draw title uView.setCursor(16, 0); uView.puts("Swipe!"); uView.display(); apds_int.enable_irq(); while(1) { // If interrupt, display gesture on MicroOLED if( isr_flag == 1 ) { apds_int.disable_irq(); handleGesture(); isr_flag = 0; wait_ms(500); uView.display(); apds_int.enable_irq(); } // Wait before next reading wait_ms(100); } } void interruptRoutine() { isr_flag = 1; } void handleGesture() { bool do_clear = true; // Draw symbol based on gesture if ( apds.isGestureAvailable() ) { switch ( apds.readGesture() ) { case DIR_UP: drawArrowUp(); break; case DIR_DOWN: drawArrowDown(); break; case DIR_LEFT: drawArrowLeft(); break; case DIR_RIGHT: drawArrowRight(); break; case DIR_NEAR: drawCircle(); break; case DIR_FAR: drawX(); break; default: do_clear = false; } } // Let symbol sit on screen for a while, then clear if ( do_clear ) { uView.clear(PAGE); uView.setCursor(16, 0); uView.puts("Swipe!"); } } void drawArrowUp() { uView.clear(PAGE); uView.line(27, 43, 37, 43); // Bottom: over 10 uView.line(27, 43, 27, 18); // Legs: Up 25 uView.line(37, 43, 37, 18); // Legs: Up 25 uView.line(27, 18, 17, 18); // Head: Over 10 uView.line(37, 18, 47, 18); // Head: Over 10 uView.line(17, 18, 32, 3); // Tip: Over 14, up 15 uView.line(47, 18, 32, 3); // Tip: Over 14, up 15 uView.display(); } void drawArrowDown() { uView.clear(PAGE); uView.line(27, 5, 37, 5); // Bottom: over 10 uView.line(27, 5, 27, 30); // Legs: Up 25 uView.line(37, 5, 37, 30); // Legs: Up 25 uView.line(27, 30, 17, 30); // Head: Over 10 uView.line(37, 30, 47, 30); // Head: Over 10 uView.line(17, 30, 32, 45); // Tip: Over 14, up 15 uView.line(47, 30, 32, 45); // Tip: Over 14, up 15 uView.display(); } void drawArrowLeft() { uView.clear(PAGE); uView.line(52, 19, 52, 29); // Bottom: up 10 uView.line(52, 19, 27, 19); // Legs: over 25 uView.line(52, 29, 27, 29); // Legs: over 25 uView.line(27, 19, 27, 9); // Head: up 10 uView.line(27, 29, 27, 39); // Head: down 10 uView.line(27, 9, 12, 24); // Tip: over 15, down 14 uView.line(27, 39, 12, 24); // Tip: over 15, down 14 uView.display(); } void drawArrowRight() { uView.clear(PAGE); uView.line(12, 19, 12, 29); // Bottom: up 10 uView.line(12, 19, 37, 19); // Legs: over 25 uView.line(12, 29, 37, 29); // Legs: over 25 uView.line(37, 19, 37, 9); // Head: up 10 uView.line(37, 29, 37, 39); // Head: down 10 uView.line(37, 9, 53, 25); // Tip: over 15, down 14 uView.line(37, 39, 52, 24); // Tip: over 15, down 14 uView.display(); } void drawCircle() { uView.clear(PAGE); uView.circle(32, 24, 20); uView.display(); } void drawX() { uView.clear(PAGE); uView.line(12, 4, 52, 44); uView.line(12, 44, 52, 4); uView.display(); }
Here is a video from Sparkfun showing all the implemented gestures:
Changes
Revision | Date | Who | Commit message |
---|---|---|---|
0:c04b49e0a678 | 2015-04-10 | synvox | first working version |