Measuring time difference between analogue IR sensors

I am attempting to build a project that will emulate a drum pad when finished, but a projection drum pad. To do this I have designed a method of reading IR reflections using several Sharp GP2Y0 analogue output sensors.

In order to attain a velocity value, I would like to place one sensor above the other and have code to decipher the difference between the two (time difference) to find out how quickly the user has hit the surface.

Currently I have my code working for a single sensor, but adding a second layer for velocity is proving difficult. The code at the moment looks for movement between certain distances and will output a MIDI signal, but only for a signal sensor.

Here is my code, any help would be really appreciated:

#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();

int currentvalA = 0;
int previousvalA = 0;
int valA = 0;                         // value to store sensor A
const int valchangeA = 40;    //motion change value
int del = 0;                          //variable delay value


void setup(){
   MIDI.begin(MIDI_CHANNEL_OMNI);    // Launch MIDI on all channels
   Serial.begin(115200);
   int del = analogRead(A0);
}

void loop(){  
 currentvalA = analogRead(A4);  
 valA = abs(previousvalA - currentvalA);
 
 if(currentvalA <= previousvalA + valchangeA || currentvalA >= previousvalA - valchangeA){ //if change is large enough
 
 if (currentvalA < 500 && currentvalA > 450){ //drum pad 1 parameters (20cm away, pad size 5cm)
   
   if (valA >= valchangeA){ //if there has been enough of a difference in movement
       MIDI.sendNoteOn(30,100,1);  // Send a Note (pitch 42, velo 100 on channel 4)
       delay(500)/*delay(del)*/;   // Delay value is variable (pot in A0)
       MIDI.sendNoteOff(30,100,1);   // Stop the note
   }
 }
 
 else if (currentvalA < 400 && currentvalA > 350){ //drum pad 2 parameters (30 cm away, pad size 5cm)
   if (valA >= valchangeA){ 
       MIDI.sendNoteOn(50,100,1);
       delay(500)/*delay(del)*/;
       MIDI.sendNoteOff(50,100,1);
   }
 }
 
 else if (currentvalA < 300 && currentvalA > 260){ //drum pad 3 parameters (40 cm away, pad size 5cm)
   if (valA >= valchangeA){ 
       MIDI.sendNoteOn(70,100,1);
       delay(500)/*delay(del)*/;
       MIDI.sendNoteOff(70,100,1);
   }
 }
   else if (currentvalA < 250 && currentvalA > 200){ //drum pad 4 parameters (50 cm away, pad size 5cm)
   if (valA >= valchangeA){ 
       MIDI.sendNoteOn(90,100,1);
       delay(500)/*delay(del)*/;
       MIDI.sendNoteOff(90,100,1);
   }
 }
previousvalA = currentvalA; //set the previous value at end of loop
//Serial.println(currentvalA);
}
}

Slight update: I have tried using millis() to function as the time constants of the two sensors to then be compared like so (where difference = velocity value):

long SensorATime = 0L;
long SensorBTime = 0L;
long difference = 0L;

difference = SensorATime - SensorBTime;

SensorATime = millis()

-Rest of code-

SensorBTime;

I know that this is wrong but I feel like I'm getting a bit closer....

I would like to place one sensor above the other and have code to decipher the difference between the two (time difference) to find out how quickly the user has hit the surface.

Why use two sensors? Just use the one sensor and take two readings.

I have tried using millis() to function as the time constants of the two sensors

Yes that is the way to do it but you haven't posted any relevant code.
That first code was a mess and way way too complex for what you are trying to do.

Grumpy_Mike:
Why use two sensors? Just use the one sensor and take two readings.
Yes that is the way to do it but you haven't posted any relevant code.
That first code was a mess and way way too complex for what you are trying to do.

The sensors read from 1 direction, and this is being used for the separation of the 'active areas', or drum pads. So to gain another variable with the pad, it makes sense to me that the harder someone should strike the surface, the higher the velocity of the MIDI note.

The code I have posted does what I need it to do, at the moment it is slightly messy but I'm somewhat of a novice coder and am trying to find the best way to organise it at the moment.