Generally, you don't use attachInterrupt for reading sensors unless you are dealing with things that happen within milliseconds, or that need to be timed accurately to the microsecond.
If you are doing job A that takes a while, and you need to occasionally handle job B too, then you need to write your code so that it can do a little bit of job A at a time.
void loop() {
do_a_slice_of_job_A();
maybe_do_job_B();
}
To accomplish this, you need to keep track of where you are inside job A using some global variables.
Let's say that job A is "count from 1 to 1000 and print out the numbers". The simple way to do it is:
void loop() {
for(int counter = 1; counter<=1000; counter++) {
Serial.println(counter);
}
}
But if you want to be able to start and stop the counter, then that loop needs to be unrolled and the state needs to go in some global variables:
int counter = 1;
void loop() {
do_some_counting();
}
void do_some_counting() {
if(counter<=1000) {
Serial.println(counter);
counter ++;
}
}
With the job of counting split up like that, then you can write code to start and stop the counting, and conditionally do the actual work:
boolean counting = false;
void main() {
if(!counting && digitalRead(startCountingPin)==LOW) {
counting = true;
counter = 1;
}
else
if(counting && digitalRead(stopCountingPin)==LOW) {
counting = false;
Serial.println("STOPPED COUNTING.");
}
if(counting) {
do_some_counting();
}
}