APDS-9960 different sensors in one sketch

Hello all,

is there anybody out there who managed to get the gesture and the color sensor work in one sketch? And if yes, which library should I use.

My plan was to have a gadget that waits for a certain gesture, then lights up some LEDs and then tells the color of an object enlighted by the leds.

Thanks in advance

Thomas

Using the Arduino_APDS9960 library, I found that I needed to call APDS.begin() again before the color sensor reads started working.

Interestingly, a FullExample example sketch was added in the latest 1.0.3 release of the library that demonstrates the gesture, color, and proximity features all being used in the same sketch. If you remove the proximity sensor code then the color sensor readings stop working so there is something wrong with the library that makes it only work correctly in the specific configuration of the FullExample sketch. I notice that even to get that working, they had to fix a bug in the library:

so I suspect something similar needs to be extended to the color sensor code. I had a look at the library code, but I am having trouble figuring out exactly what would need to be done. Well, at least it works fine with the workaround of calling APDS.begin() again so it's not so bad.

I almost forgot; here is my test sketch:

#include <Arduino_APDS9960.h>

bool gestureDetected = false;

void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!APDS.begin()) {
    Serial.println("Error initializing APDS9960 sensor!");
  }

  Serial.println("Waiting for gesture");
}
void loop() {
  if (APDS.proximityAvailable()) {
    APDS.readProximity();
  }
  switch (gestureDetected) {
    case false:
      if (APDS.gestureAvailable()) {
        // a gesture was detected, read and print to serial monitor

        int gesture = APDS.readGesture();
        gestureDetected = true;
        APDS.begin(); // this is required to enable the color sensor after using the gesture sensor
        switch (gesture) {
          case GESTURE_UP:
            Serial.println("Detected UP gesture");
            break;
          case GESTURE_DOWN:
            Serial.println("Detected DOWN gesture");
            break;
          case GESTURE_LEFT:
            Serial.println("Detected LEFT gesture");
            break;
          case GESTURE_RIGHT:
            Serial.println("Detected RIGHT gesture");
            break;
          default:
            // ignore
            break;
        }
      }
      break;
    case true:
      if (APDS.colorAvailable()) {
        int r, g, b;

        // read the color
        APDS.readColor(r, g, b);

        // print the values
        Serial.print("r = ");
        Serial.println(r);
        Serial.print("g = ");
        Serial.println(g);
        Serial.print("b = ");
        Serial.println(b);
        Serial.println();
      }
  }
}

Thanks a lot, I'll try this out today