arduino123456789:
HelloKnow any a way to do a scketch in a schetch?
Example: when scketch1 on the arduino detect a button interupt then open schetch2 on the arduino.
Can any give a example or tell how to do this please?Thanks
As Boguz says, state machine will let you do it.
But not everything will be controlled by the general process-state. The button must be free to detect quickly at any time and debounced as well unless the button is hardware-debounced.
You don't need or want an interrupt unless that's one very special no-bounce button that HAS to detect a change in button state (ON/OFF) quicker than about 10 millis. This would include light-beam interrupt, magnetic sensing, and in general non-physical-contact-mashing sensing methods. If by button you mean actual finger-press buttons or you'd like to learn a bit about those then keep reading.
Button/contact bounce:
Most buttons, especially cheap buttons (I use jumpers for real cheap buttons just to test ideas) do not make solid contact at once but can take many millis of back and forth between ON and OFF reads done at high speed.
Fast code, the kind you want, will see several to 20+ button presses in a single bounce.
Arduino when not tied down by blocking code will look at that button on the 10's of microsecond level or faster.
What to do is have code that only watches the button and waits for for the button state to settle down, to stay ON or OFF for a certain amount of time like 5 millis.
OTOH you can use delay-code and assume it will be right. It will take longer than needed to ensure always being "right" and keep anything else from running until that wastey wait is done, UGH.
Neither way needs an interrupt. The action of buttons is far slower with far more slop than that. But no worries about that since the hand pressing the button and the mind behind it are 100 times slower and can't possibly notice the bit of time spent debouncing. To the human, it's all instant. For most wants, that is just great. You don't need an interrupt to achieve that, just nothing in the rest of your code that hangs button checking up!
You do not want delay() or long sequences of operations stopping anything like button/sensor/timing code, those are hang-ups.
Yump, all that just for a button, real-time code just to make sure it's done being pressed or released! And once it has the button code changes a variable that triggers the sketch2 code. Sketch2 does not trigger on the button pin but rather the abstracted, cleaned-up, for-sure-the-button-is-staying-ON-or-OFF state flag to act upon.
And I hope you have no doubt about it given all the why and how above.
May that be the hardest part of your project, but Murphy tells me it's very unlikely.