How do I do Interrupts for time and touch?

I need to set up an interrupt in my code so that no matter what it's doing it can immediately react to someone touching the screen. This screen has a tp-irq pin, so I think I can do that.

I also need an interrupt so that every time the seconds in my RTC module change, it will immediately update the screen.

Does anyone know how to do this? Or would I be better off polling for both of these things?

I have to attach the code in a zip file because it is too big to copy and paste.

Exactly what is your time frame for "immediately"?

Not this again.

1 Like

A good start would be to read this Nick Gammon, Interrupts

1 Like

@Paul_KD7HB
Before my finger has even left the screen I want it to have reacted. Basically as fast as a mega can do something (1/16000000 of a second is the fastest, maybe not that fast, but fast enough that I never have to touch it twice because it didn't respond)

@anon57585045
What do you mean?

@JohnRob
I've already read that, however I don't know how to make it work because the touch screen interrupt pin is on pin #44 of my mega. Also, I don't think I can use a pin to trigger the interrupt for the clock to update the screen.

Well, touching it twice problem is not a timing problem, but coding problem. Would 1 millisecond be soon enough? Would 10 milliseconds be soon enough?

Beginners often mistake interrupts as a panacea for multitasking problems.

2 Likes

@Paul_KD7HB
I'd be happy with 5 milliseconds. And yes, when I put a delay in the code the touch doesn't respond. I thought that was a timing issue? But the seconds need to change every time a second ticks by, so I guess 998 milliseconds for the clock would be fine.

@anon57585045

What would you suggest then? There is so much happening that can't be delayed, but polling everything always ends up with something being delayed.

then you coded it incorrectly.

3 Likes

Then you aren't doing it right, or you are doing other things wrong.

Give polling a fair shot and show us the code that disappoints you when you have it working.

And then we can say oh, yes, interrupts are needed here.

More likely we can suggest alternate program structure to get the job done w/o them.

a7

2 Likes

To be fair, it could be difficult to make those changes now that 30,000(?) lines of code are already written.

1 Like

@anon57585045
That's likely. But if I knew what I'd done wrong I'd fix it. There are 1257 lines of code to go through and check and edit and change every time something doesn't work right...

@alto777
This code is jamming on the tab "Home", line #34. It goes off into the weather tab and starts hanging and jamming and nothing changes when it's supposed to. So far all I've done is polling, however after trying to fix it for days it isn't working, and I don't understand how to get rid of the delay in the Zambretti code in the weather tab while also checking if six other things have changed or not.

WeatherStation4.zip (12.4 KB)

Post a schematic as you have it wired including all ground and power connections. Also include the power supply(s). Also post links to technical information on all the hardware parts. It appears you are either supper programer to get that much code in less than I am assuming 7 days a week for 8 years. Studies have shown that the average programmer in a production environment puts out about 10 lines of code per day.

I wrote programs commercially for 30+ years and many times I had to toss the program and start over because I learned something new about the goal I was programming for and that required starting over with the new concept. Every new program is a new learning experience.

@gilshultz

The Touch screen backpacks on to the double headers, and the datalogging shield connects as they always do.

http://www.lcdwiki.com/3.95inch_Arduino_Display-Mega2560

https://www.ebay.com.au/itm/255534295635

https://docs.arduino.cc/hardware/mega-2560

https://www.ebay.com.au/itm/394009225518

@Paul_KD7HB
First I need to know how to do it before I can re-write or write anything.

@gilshultz

Those programmers are writing and fully debugging those ten lines of code. They also know how to write concise code. A new develepor writes more lines of code because he isn't as good.

image

So far this project has taken me a couple months to write the code for.

A bunch of nice but useless pictures the same as the frizzy picture. I asked for a schematic as you have it wired including all ground and power connections. Also include the power supply(s). Also post links to technical information on all the hardware parts. The link to the LCD is OK. To fix move wire 3 to, the yellow one from, the orange is, you get the idea!

If you were to start over, how would your overall logic be different?

@gilshultz
Ok. That's great. But I do not have a way to make a schematic. If you can donate some of the expensive software to create this schematic, I will be able to draw one. Otherwise, a wiring diagram will have to suffice. For most people, it isn't hard to see how a shield connects to a board - they line up and drop on. Also, I do not have datasheets for all of my modules, as most of the datasheets for them are written in chinese. If you can read chinese, you will have to find them yourself, as I can't read chinese.