I'm not sure i understood right, but maybe what you are looking is a State Machine.
State Machines work like this:
You create "States", let's say for example there are 3 States.
when your sketch starts the State is 1 and things work a certain way.
then when you press a button State becomes State 2 and it can work in a different way.
Then press again and State becomes State 3 and your sketch can still so something different.
The sketch would look something like this:
// all your variables and other needed stuff here
byte State = 0; // we will have 3 States; State 0, State 1 and State 2
// we start with State = 0
void setup(){
// all your setup code here
}
void loop(){
// check your button
// if the button was pressed
// increase State by 1
// if State is equal to 3, make it again equal to 0 - we are using only 3 States
// Check current State and run only the appropriate code
// if State is equal to 0 run just State0 code
if (State == 0) {
// Your State0 code here
}
// if State is equal to 1 run just State1 code
if (State == 1) {
// Your State1 code here
}
// if State is equal to 2 run just State2 code
if (State == 2) {
// Your State2 code here
}
}
State Machines are very useful and allow you to run specific pieces of code (you can kind of think of them as little sketches) according to the State the sketch is currently in.
I hope you got the idea of what i meant, if not just let us know and we can try to explain it better. If you look for State Machine in google you will find a lot of results which might also help you.
![]()