Attaching Interrupt with timeout

I am trying to attach an interrupt with 1ms timeout. When the interrupt occurs, I want the remainder of the program to be executed, else I want it to print an error.

I understand that we can use the Function in the attachInterrupt() to execute small piece of code when the Interrupt occurs, but I want to execute the remainder of my program (with several functions) with return values, How can I achieve this ?

Below is the code that I am working with.

int interruptDetected = 0; // Defining a global variable

while(timeElapsed < 1)  attachInterrupt(D0,interruptFunction,FALLING);  // Timing out the attachInterrupt in 1ms and calling the interruptFunction when interrupt is detected
if(interruptDetected==1){"Here I would run the remainder of the program"};
else Serial.println('Error routine: Clock does not start');

void interruptFunction()
   interruptDetected =1;

the interrupt function should only fire once on activation of the interrupt pin. The rest of your code should continue running in the loop

void loop() {
      all your other code

take a look at this code, it has a lot of interrupts and other code intermingling

1 Like