i have two different programs of arduino which i want to merge as a single program with some logic like if a particular button is on jump to program 1 or if button is off jump to program 2 but that would be a waste of energy as button will be on or whole time program 1 is running. Is there more efficient way to do the switching. note for demonstration the arduino will be battery powered and not connected to laptop or pc.
Could be at the beginning of your loop, digitalRead for a switch and you'd go to one function or another from there.
Even then, from either function you could check that switch to go to the other function.
const byte buttonPin = 3;
void loop() {
if (digitalRead(buttonPin)) {
loop1();
}
else {
loop2();
}
}