This is the question or topic for discussion. If the program code is long or let's say very busy and messy and it does not start looping main function loop() regularly keypad function will not work properly.
To overcome this situation I have in mind to try attaching an interrupt to a keypad however this may cause some other issues
What would be the proper solution to this problem, would guys with knowledge share a solution for this?
Welcome to the forum
Then you have written the code incorrectly. The loop() function should run thousands (possibly millions) of times per second and certainly often enough to read keypad input
Please post a full sketch that illustrates the problem that you are having, using code tags when you do
That was quick, lightning struck
Thank you very much, I am nicely surprised.
It is hypothetical. I know that atmel MCU is about 16 x 10 -6 cycles in a second so if there is not much to do in loop(), theoretically it will do 16 million times loop() in a second, figuratively speaking.
If there is some nasty math calculation this going through loop() again could take quite some time and potentially keypad stroke would be missed. As I wrote above my idea to overcome this is to attach a kind of interrupt to keypad.
My question or let's say what I would like to learn before experimenting and searching the best solution for this on my own, is if someone already did this.
Then the code is inefficient and should be refactored. Use integer variables of the correct size and not floats, avoid use of sin(), cos(), tan() and pow() functions and the like whenever possible
By all means experiment with interrupts then go back and write the code properly
How many keys are there that you want to accommodate in your keypad?
I have an idea (based on 74LS148 Priority Encoder) that can handle 8 keys and consume INT0-pin and three IO lines of the UNO.
While the program is off doing nasty lengthy calcualtions, what do you need or want to hear from the keyboard?
Would not the operator of this device be expecting to be ignored, like we wait patiently for progress bars or even spoinning pizzas of death on our desktop moochines?
Even if you code an interrupt to get all the keystrokes you'd still have to mollify your existing code to respond sooner than finishing the nasty lengthy calculations.
Which modifications might well be similar to doing it without interrupts.
You may also want to rethink whether the processor and speed you have chosen is appropriate to the task(s).
a7