So you have two general sections: one that executes once, never to return once you leave it: void setup(){}; and the other program that runs from start to finish, over and over forever void loop(){}.
You can't strictly speaking make two programs run in the way you're thinking about it without void loop() somehow addressing even the part you want to ignore on subsequent iterations of that loop.
But you can certainly block sections off, go deeper within nested loops, break out or even seemingly stop the loop such as while(1); - but even that while() loop still loops within itself; that is, doesn't actually halt the program.
Think about layers of an onion as opposed to extending the length of a track, when you want to do more than one "program" at a time. Those other programs you would usually call as functions: you might have one called
void blastSlimer(){
// do the thing that blasts Onionhead
}
and just call that function within the main program like so:
blastSlimer();
Make up a whole bunch of these if you like and, using your human input thing (it is buttons?), create states of a general machine, conceptually in your case, a proton blaster.
The following sketch shows one way to approach this idea using just your Arduino and you typing numbers in the Serial Monitor, and prints back the sort of feedback you might expect if you added in all the real equipment. This shows one outer layer of an onion, if you will, but you could build state machines within each state, and substituting the Serial user input for your buttons or whatever.
char mode;
const int light = 3;
const int pump = 4;
const int fan = 5;
void setup() {
Serial.begin(115200);
pinMode(light, OUTPUT);
pinMode(pump, OUTPUT);
pinMode(fan, OUTPUT);
Serial.println(F("charDrivenStateMachine"));
Serial.println();
Serial.println(F("Type 0-7 to change functions"));
Serial.println();
mode = '0'; // start state variable at mode 0
modeZero(); // let us know and init devices to off
}
void loop() {
if (Serial.available() > 0) {
mode = Serial.read();
switch (mode) {
case '0':
modeZero();
break;
case '1':
modeOne();
break;
case '2':
modeTwo();
break;
case '3':
modeThree();
break;
case '4':
modeFour();
break;
case '5':
modeFive();
break;
case '6':
modeSix();
break;
case '7':
modeSeven();
break;
}
}
}
void modeZero() {
Serial.println("mode 0");
Serial.println("light off, pump off, fan off");
Serial.println("");
allOff();
}
void modeOne() {
Serial.println("mode 1");
Serial.println("light on, pump on, fan on");
Serial.println("");
allOn();
}
void modeTwo() {
Serial.println("mode 2");
Serial.println("light on, pump on, fan off");
Serial.println("");
lightAndPump();
}
void modeThree() {
Serial.println("mode 3");
Serial.println("light off, pump on, fan on");
Serial.println("");
fanAndPump();
}
void modeFour() {
Serial.println("mode 4");
Serial.println("light on, pump off, fan on");
Serial.println("");
lightAndFan();
}
void modeFive() {
Serial.println("mode 5");
Serial.println("light on, pump off, fan off");
Serial.println("");
justLight();
}
void modeSix() {
Serial.println("mode 6");
Serial.println("light off, pump on, fan off");
Serial.println("");
justPump();
}
void modeSeven() {
Serial.println("mode 7");
Serial.println("light off, pump off, fan on");
Serial.println("");
justFan();
}
void allOff() {
digitalWrite(light, LOW);
digitalWrite(pump, LOW);
digitalWrite(fan, LOW);
}
void allOn() {
digitalWrite(light, HIGH);
digitalWrite(pump, HIGH);
digitalWrite(fan, HIGH);
}
void lightAndPump() {
digitalWrite(light, HIGH);
digitalWrite(pump, HIGH);
digitalWrite(fan, LOW);
}
void fanAndPump() {
digitalWrite(light, LOW);
digitalWrite(pump, HIGH);
digitalWrite(fan, HIGH);
}
void lightAndFan() {
digitalWrite(light, HIGH);
digitalWrite(pump, LOW);
digitalWrite(fan, HIGH);
}
void justLight() {
digitalWrite(light, HIGH);
digitalWrite(pump, LOW);
digitalWrite(fan, LOW);
}
void justPump() {
digitalWrite(light, LOW);
digitalWrite(pump, HIGH);
digitalWrite(fan, LOW);
}
void justFan() {
digitalWrite(light, LOW);
digitalWrite(pump, LOW);
digitalWrite(fan, HIGH);
}
There is a great video I encourage you to watch as state machines (and state change detection) are two critical concepts to understand when approaching projects that have some semblance to beyond very basic movie props or video games.
As a super amateur hobbyist myself with no background in electronics, Arduino, coding - the state machine approach was the "aha" concept that took me from blinking an LED to blinking and LED while doing something else but only sometimes when I really wanted it to. Clear as mud?