Something like this:
volatile unsigned int signal;
volatile bool haveSignal;
ISR(TIMER2_COMPA_vect){
reading = analogRead(pulsePin);
haveSignal = true;
}
void loop() {
if (haveSignal) { // Yoo hoo! Got a new signal!
haveSignal = false; // Record that we handled the new signal.
noInterrupts();
unsigned int signal = reading; // So to prevent the value from changing while we work onit.
interrrupts();
processSignal(signal);
}
// Whatever else loop() has to do.
}
void processSignal(unsigned int signal) {
// Do something useful with your newly acquired data.
// But don't take too long here or you will still miss events!
}