Touch LCD interrupt

I'm using the UTFT library on a Mega, which I'm using to read a bunch of sensors and report it to the screen. My problem is that reading all the sensors takes some time and if I touch the screen while the sensors are being read then the touch doesn't register. The sensors are read every 5 seconds so these ignored touches can happen pretty frequently. Obviously I could read the data less often, but I'm wondering if there is a way to solve the problem with interrupts or some other software technique. Does anyone know if the UTFT is already using an interrupt to get touch input data? If not, can I set up an interrupt that happens whenever I touch the screen? If so, is there a way to re-write my code to avoid this inconvenience?

theoracle39:
If so, is there a way to re-write my code to avoid this inconvenience?

Yes, simply write it properly. :wink:

No sensor read will take more than a tiny fraction of a second. I suspect you are using improper real-time techniques, such as using "delay()" calls or "wait" loops. That is not how you write interactive code.

Your "loop" code should be cycling at something in the order of a hundred times per second at least. If you are reading a number of sensors, this should probably be performed by something resembling a "switch" statement which selects one sensor to read on each pass through the loop. If there is any need to wait for the result of a sensor reading, you set an "alarm" variable to the appropriate value of "millis()" forward of the current value, and each time this part of the loop is encountered, you see whether that time has arrived, in which case you complete the sensor reading, if not, pass directly on to the next function on the loop. One of the functions in the loop is to check on your screen touch, so this is performed as frequently as you check on (any of) the sensors.


Oh yes.

First rule (or perhaps the second ...) of the help forum:

You want to know what is the problem with your code?

Post it! Put it inside "code" tags generated using the code [ # ] button above the submission window.

Thanks for your response. I thought about posting the code, but it's very long and I didn't want any potential helpers to get discouraged by having to wade through pages and pages of code. It seems like a simple enough solution to read one sensor during each loop of the code rather than reading all the sensors together. I'll have to check if the code waits for a response from the any of the sensors.