开发者

Is it possible to set up interrupts on each pin of Arduino Mega?

开发者 https://www.devze.com 2023-02-19 22:31 出处:网络
We would like to monitor 35 inputs. 20 in the x direction and 15 in the y direction. We are t开发者_StackOverflow社区hinking of having an interrupt for each input, so that every time there is a change

We would like to monitor 35 inputs. 20 in the x direction and 15 in the y direction. We are t开发者_StackOverflow社区hinking of having an interrupt for each input, so that every time there is a change we can take some action, but how do we set up interrupt on each pin?

Or is there another way to do it without interrupts?


As I know Arduino can't do this. But you can use an infinite loop and poll each line. You can store the old value for each input and compare it to the current value. It seems that an infinite loop in Arduino is pretty cheap. This method is somewhat more difficult if you are doing calculations between the signal changes.

Another way is to use only one interrupt line which would initiate the same polling routine that will compare old and current values on inputs.

The idea of using separate interrupts seems too fragile to me. While processing the interrupt usually other interrupts are disabled so you can lose the input change signals in this time period. Have you anticipated it in your hardware design?

Probably if you elaborate on your requirements a little bit it would be simpler to suggest a solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号