My code has changed about 10 times since I had a working interrupt with the IR photodiode. It originally had a simple counter that printed every 100 times it triggered the interrupt. That worked great. I added the timer and the IR counter stopped working. So, this code is a summary of the key pieces:
#include <TimerOne.h>
int count = 0;
float time = 0.0;
int runCalc = 0;
void counter() {
count++;
}
void stepTime() {
time += 0.2;
runCalc = 1;
}
void calc() {
const int tab = 9;
Serial.print(time);
Serial.write(tab);
Serial.println(count);
count = 0;
runCalc = 0;
}
void setup() {
Serial.begin(9600);
Timer1.initialize(200000); // set a timer to 5 Hertz
Timer1.attachInterrupt(stepTime);
attachInterrupt(0, counter, FALLING);
}
void loop() {
if (runCalc) calc();
}