是否可以在Arduino Mega的每个引脚上设置中断?
我们想要监控 35 个输入。 x 方向为 20 个,y 方向为 15 个。我们正在考虑为每个输入设置一个中断,以便每次发生变化时我们都可以采取一些操作,但是我们如何在每个引脚上设置中断呢?
或者有其他方法可以在不中断的情况下完成此操作吗?
We would like to monitor 35 inputs. 20 in the x direction and 15 in the y direction. We are thinking 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知Arduino不能做到这一点。但您可以使用无限循环并轮询每一行。您可以存储每个输入的旧值并将其与当前值进行比较。 Arduino 中的无限循环似乎相当便宜。
如果您要在信号变化之间进行计算,则此方法会稍微困难一些。
另一种方法是仅使用一个中断线,该中断线将启动相同的轮询例程,该轮询例程将比较输入上的旧值和当前值。
使用单独中断的想法对我来说似乎太脆弱了。在处理中断时,通常会禁用其他中断,因此您可能会在此时间段内丢失输入变化信号。您在硬件设计中是否预见到了这一点?
如果您稍微详细说明一下您的要求,那么建议解决方案可能会更简单。
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.