Ich denke, du brauchst keinen Interrupt, sondern nur eine Flankenerkennung (state change detection).
Dazu gibt es einen netten Sketch in den Beispielen: File/Beispiele/02.Digital/StateChangeDetection
Leicht modifiziert, könnte er für deine Zwecke etwa so aussehen:
const byte TSOP_PIN = 3;
const byte IR_LED_PIN = 6;
int einwuerfe = 0;
boolean lbState; // current state of light barrier
boolean lastLbState; // previous state of light barrier
void setup() {
Serial.begin(9600);
pinMode(TSOP_PIN, INPUT);
tone(IR_LED_PIN, 36000);
}
void loop() {
// read the light barrier input pin:
lbState = digitalRead(TSOP_PIN);
// compare the light barrier state to its previous state
if (lbState != lastLbState) {
// if the state has changed, increment the counter
if (lbState == HIGH) {
// if the current state is HIGH then the light barrier went from off to on:
einwuerfe++;
Serial.println("on");
Serial.print("einwuerfe: ");
Serial.println(einwuerfe);
} else {
// if the current state is LOW then light barrier went from on to off:
Serial.println("off");
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
lastLbState = lbState;
}
Ich weiß zwar nicht, wo sich die Lichtschranke befindet, gehe aber davon aus, dass es in der Nähe des Einwurfschlitzes ist. Dann könnte es etwa so funktionieren. Eine längere Verweildauer und Unterbrechung der Lichtschranke wird dabei nur einmal gezählt.