Attaching Interrupt to an Array?

Hello everyone,

So I am working on one of those SumoBots and I have 4 IR sensors that are used to detect a change from black floor to white floor. I am using QTR-1RC and its library. The example codes used an array to store their multiple sensors in.

The problem is, whenever one of these sensors detects a change in color, it should immediately stop what it's doing and move away from the line, so I figured an interrupt would be perfect. However, I am trying to reference a specific pin from the array to send it to a specific method. Unfortunately, the code will not compile. It gives this error message:

SumoRobot:63: error: macro "digitalPinToInterrupt" passed 3 arguments, but takes just 1
attachInterrupt(digitalPinToInterrupt(sensorValues[0], retreat, FALLING);
exit status 1
macro "digitalPinToInterrupt" passed 3 arguments, but takes just 1

#define numSensor 4 // number of line detectors attached
#define timeOut 2500 //waits 2500 microseconds for sensor outputs to go low
#define emitterPin 27 //emitter is controlled by digital pin 27

// line sensors 0 through 4 are connected to analog inputs 18 through 21, respectively
QTRSensorsRC qtrrc((unsigned char[]) {18, 19, 20, 21},numSensor, timeOut, emitterPin);
unsigned int sensorValues[numSensor];

void setup () {
attachInterrupt(digitalPinToInterrupt(sensorValues[0], retreat, FALLING);

P.S. I am using a Mega 2560

it was a freaking close parathesis after sensorValues[0]. I have been pulling my hair out for hours now. Fml

But did it work after closing the bracket?

But did it work after closing the bracket?

Did you have to revive an old thread? I always wonder how people manage to find them.

OP is obviously happy as he/she did not come back in this thread.

Do you have the same problem? Or have something to add?

I always wonder how people manage to find them.

I’m sure its better to revive an old one with new information for the benefit of all. Perhaps in a mkore constructive way tough.

I had the same problem, the error message is a bit obscure.
The correct syntax for this handler is

attachInterrupt(digitalPinToInterrupt(pin mode), handler, mode);

on the code above this would translate to

attachInterrupt(digitalPinToInterrupt(sensorValues[0]), retreat, FALLING);