APDS-9960 gestures without external interrupt?

Hello,

I’m working on a project which incorporates an APDS-9960 gesture sensor, I’m using the library in the link here.

I have everything working as per the example, but I need to be able to detect gestures without using the external interupt pin on the Arduino. I have altered the code in the example, which is below and everything works (including gestures), apart from the fact that the code pauses and it wont run the rest of the code at the bottom if an object is within range of the gesture sensor. As soon as the gesture sensor is pointing at thin air the rest of the code starts to work again.

Could someone kindly explain how I can go about getting around the requirement for an external interrupt with this library?

Many thanks.

#include <Wire.h>
#include <SparkFun_APDS9960.h>

SparkFun_APDS9960 apds = SparkFun_APDS9960();

void setup() {
  // Initialize APDS-9960 (configure I2C and initial values)
  if ( apds.init() ) {
    Serial.println(F("APDS-9960 initialization complete"));
  } else {
    Serial.println(F("Something went wrong during APDS-9960 init!"));
  }
  
  // Start running the APDS-9960 gesture sensor engine
  if ( apds.enableGestureSensor(true) ) {
    Serial.println(F("Gesture sensor is now running"));
  } else {
    Serial.println(F("Something went wrong during gesture sensor init!"));
  }
}

void loop() {
  if ( apds.isGestureAvailable() ) 
  {
    switch ( apds.readGesture() ) {
      case DIR_UP:
        Serial.println("RIGHT");
        break;
      case DIR_DOWN:
        Serial.println("LEFT");
        break;
      case DIR_LEFT:
        Serial.println("UP");
        break;
      case DIR_RIGHT:
        Serial.println("DOWN");
        break;
      case DIR_NEAR:
        Serial.println("NEAR");
        break;
      case DIR_FAR:
        Serial.println("FAR");
        break;
      default:
        Serial.println("NONE");
    }
   }
   //further code which never runs here which looks at physical external switches etc
}

I need to be able to detect gestures without using the external interupt pin on the Arduino.

Get over it. To detect the changes in acceleration that define a gesture, with any degree of reliability, polling isn't anywhere near fast enough.

   //further code which never runs here which looks at physical external switches etc

That was a stupid thing to redact. How are we supposed to guess what the hell is wrong with code we can't see?

I guess you just came here to whine.

I am sorry that I appear to have offended you with my post, I haven’t ‘come here to whine’, I’m not entirely sure what I’ve done to deserve such an aggresive reply? It is a genuine post just looking for assistance as a relative newbie to Arduino.

The rest of my code which I didn’t bother to post is just purely looking at some digital inputs and controls some digital outputs. It doesn’t do anything which I can see would cause a problem for the rest of the code, I deliberately left it out to try to make the post as short and easy as possible for people to read without wasting their time with irrelevant code out of courtesy to you and others.

#include <Wire.h>
#include <SparkFun_APDS9960.h>

SparkFun_APDS9960 apds = SparkFun_APDS9960();

const int OutputPin1 = 8;
const int InputPin1 = 9;

void setup() {
  pinMode(InputPin1, INPUT_PULLUP);
  pinMode(OutputPin1, OUTPUT);
  // Initialize APDS-9960 (configure I2C and initial values)
  if ( apds.init() ) {
    Serial.println(F("APDS-9960 initialization complete"));
  } else {
    Serial.println(F("Something went wrong during APDS-9960 init!"));
  }
  
  // Start running the APDS-9960 gesture sensor engine
  if ( apds.enableGestureSensor(true) ) {
    Serial.println(F("Gesture sensor is now running"));
  } else {
    Serial.println(F("Something went wrong during gesture sensor init!"));
  }
}

void loop() {
  if ( apds.isGestureAvailable() ) 
  {
    switch ( apds.readGesture() ) {
      case DIR_UP:
        Serial.println("RIGHT");
        break;
      case DIR_DOWN:
        Serial.println("LEFT");
        break;
      case DIR_LEFT:
        Serial.println("UP");
        break;
      case DIR_RIGHT:
        Serial.println("DOWN");
        break;
      case DIR_NEAR:
        Serial.println("NEAR");
        break;
      case DIR_FAR:
        Serial.println("FAR");
        break;
      default:
        Serial.println("NONE");
    }
   }
  if (digitalRead(InputPin1) == LOW)
  {
    digitalWrite(OutputPin1, HIGH);
    Serial.println("ON");
  }
  else
  {
    digitalWrite(OutputPin1, LOW);
    Serial.println("OFF");
  }
}

As previously stated, the code works fine so long as the gesture sensor is aimed at thin air. It also detects gestures, but as soon as an object is within its range (which is stationary), the rest of the code ceases.

neilbaker86: Could someone kindly explain how I can go about getting around the requirement for an external interrupt with this library?

just curious, but WHY is it so important for you not to use the interrupt?

As PaulS rightly said, in these kind of application, using interrupt is more often than not the most suitable option. so why the need to eliminate its use?