Hi, Im developing a loooong project with an arduino mega, a keypad+lcd panel (i2c driven), RTC clock, ethernet shield, etc. I need to process keypad presses as soon as they come. Depending on what the user presses, I need to show certain information on the LCD. But this can't have any delay Also I need to periodically connect to the server to download and update files.
My issue now: The ethernet.connect function is locking everything until it returns. It has a long timeout. So if the server is responding slowly or is off, I won't get the control back into my arduino "main" until 15-20 seconds. During that time the user may be hitting keys but he won't see anything in the LCD.
So I turned to using interrupts. Twice a second my ISR is called to check for pending keypresses, and in case there's something, show it onscreen. So even if Im in the middle of an ethernet.connect funcion, it gets interrupted to attend key presses correctly.
The problem Im experiencing is that it eventually gets frozen, Im afraid it has to deal with calling complex functions from within my ISR. The theory says you should be really short within ISR calls, do as little as you can and not call complex functions. In my case, as I have to show the pressed key in the LCD, I need to read the key press, show a string, show a number, etc, all through I2c communication.
Does anyone figure out a better way to do this? I was thinking of using mutithreading but it looks like Arduino Multithreading is not "real" so it will only help in "organizing" my source code but won't really alter the way it's run.
Thanks in advance!