attachInterrupt should be placed in void setup() or void loop()?I have seen almost everywhere that it is placed in void setup() but what if i place it in void loop()?
I am probably too late with my answer, as it takes 5 minutes to try it out and see if it works and almost 20 minutes have passed.
The answer is "it can be in both", but since it's called once most people put it in setup().
Nothing, because in order for it to do anything you have to first detach the interrupts.
However, if you do use it in the loop function then you are marking your code as being written by someone who does not know what they are doing. And you wouldn't want that would you?
As already said, there is no rigid rule. The attachInterrupt
method can be applied wherever it is needed. You can even call attachInterrupt inside the same interrupt you are attaching.
No, it is not required, because attaching the new handler detached the previous.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.