4 ms·
TIL there is an Arduino mouse library that handles 3 buttons and 2 optical encoders. Cool. Good point, seems like X1 will be low after the x interrupt occurs.
by Tempest1981 5y ago
TIL there is an Arduino mouse library that handles 3 buttons and 2 optical encoders. Cool.
Good point, seems like X1 will be low after the x interrupt occurs. So they could read just x2 only. But my guess is that they were testing the xint() and yint() functions using polling, then configured the interrupts later.
- floren 5y agoYour guess is correct. I should clean up the code, though.
- tzs 5y agoAlthough the author has verified your guess is correct, there is actually a reason one might want to check the pin in the interrupt handler. If the switch bounces you can get spurious interrupts. If the maximum bounce period is under the time it takes the Arduino to process the interrupt and call your handler so that you can be sure the pin will be done bouncing by the time your code runs than you can handle this by simply treating the interrupt as an opportunity to poll. If the switch bounce can be longer than that then you might need software debouncing. Probably the simplest approach there is keep track of the last interrupt time and only treat interrupts as real if they do not occur too soon after the previous interrupt.