[sorted] delay() & equivalent not working.

majenko:

cowasaki:

majenko:
You're not using delay() or millis() from within an interrupt are you ...?

Yes, a slow one. Didn't know that was an issue but it does make sense thanks.

delay() checks the return value of millis() against a timeout value. millis() returns the value of a counter variable. That counter variable is updated once a millisecond by a timer driven interrupt routine.

That interrupt routine cannot run while you are in your interrupt routine, so the counter never increases.

Interrupt routines should be kept as short as possible so that other interrupts have a chance to fire. The "proper" way of doing what you want is to set a flag (and maybe a couple of variables - x/y coordinates for example) in the interrupt routine, and then watch for that flag being set in the main loop. Only in the main loop would you do slow and intensive operations like drawing widgets on a screen.

You need to separate the "capturing" of the event and the "reacting to" the event. The capturing is done in the interrupt by setting a flag that says this event has happened. The reacting to is done in the main loop by it realising that the event happened recently, so it does what is needed. The capturing wants to be instant and reliable (interrupt) but the reacting to can be slightly delayed by a few milliseconds without any adverse consequences (and maybe not even being noticable) - the event has already been captured.

Thanks for your reply but I actually already understand all this anyway. My interrupt handler is very short and uses its own interrupt on the Due (checked beforehand to make sure it was clear), if it detects an event it needs to deal with then it halts the interrupt whilst it updates the screen etc then restarts it.

Thanks to everyone who tried to help but majenko got it..

the only thing here I didn't realise was that delay() and millis() didn't work inside an interrupt.

millis() could have been updated by another interrupt hence me trying to use the loop alternative myself to see if delay() was the issue.

It was only done like this as a quick kludge to check the display before connecting the process to the on button press and on button release events.