I am completely new to both Nextion and Arduino so please be kind
I want to have a button on the nextion display that triggers an interrupt to stop a piece of code from functioning - is this possible and some pointers on how to would be hugely appreciated
Can the Nextion change the state of say pin 2 to drive a change triggered interrupt ?
An interrupt does just that! It interrupts the instruction flow and when the interrupt code is complete the instruction flow is begun again at the exact point it was interrupted. That is not what you are looking for. You need to code for the button push where you need to stop your code.
All the example code in my Nextion tutorial is non-blocking and multi tasking so you can also learn from that.
Edit:
I just found your other topic, I note it uses delay(), that has to go, see the tutorials above. I also note you are using the official Nextion library, I have yet to encounter anyone having much success with that. Finally I note that you have an awful lot of buttons and things, far too many for someone who is still learning the basics, it just looks way to complicated.
Thanks Perry - I'll go through what you have suggested - my project will control some nema motors on a millling machine - there is a lot to do but I'll get there bit by bit
for(int x = 0; x < 800; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
I don't know much about driving motors but there are others here who do, hopefully one of them can advise you how to eliminate loops like that.
Edit:
As commented I don't know much about driving motors, but if I did want to know I'd start by reading the posts in Motors, Mechanics, Power and CNC - Arduino Forum for ideas. If sub-millisecond pulses and accurate timing are required I'd read the data sheet for the processor, particularly the section on counters and timers, and work out how to use the timers to generate interrupts at the required interval to generate the pulses to the motor.