Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 9 months ago.
SparkFun_APDS9960
Do you have an example main program that shows how to use your library: SparkFun_APDS9960? If so, I could use the help.
Question relating to:
1 Answer
8 years, 9 months ago.
Hi Marc,
yes, i have a small Test-Program for the library. I did it for the LPC11U68 board and it uses my adapted SparkFun-MicroOLED library for display of the gestures on a 64 x 48 pixel OLED screen, but you can easily change the Test-Program for a different mbed-platform and use serial for gesture detection output.
You can also have a look at this youtube-video from sparkfun, that explains the 6 gestures implemented in the library:
If you like to have examples for use of the RGB, ambient light and proximity sensing, you can look at these Arduino code examples from SparkFun. The programs should be fairly easy to adapt for mbed, as most or all of the hardware specific stuff is in the library.
My 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(); }
Best regards
Neni