i want to change the program with a push button

it have a stoplight that i want to change between different programs, i want to run one program and when i press a button i run a different program. right now i have a potentiometer that changes how much time there is between each light change and i want to press a button and have the red light flash. can someone please show or tell me what to do, my code is in the attachment. i am also using a relay shield to switch the lights.

stoplight.ino (607 Bytes)

Please follow the forum guidelines and post your program in code tags instead of as an attachment.

Create a variable that toggles from true to false when you push your switch. When true, run function A, when false, run function B.


int programNumber = 1;

void loop() {
   int prevProgramNumber = programNumber;

   programNumber = digitalREad(button)==HIGH ? 1 : 2;

   if(programNumber != prevProgramNumber) {
     if(programNumber == 1) startProgram1();
     else if(programNumber == 2) startProgram2();

  if(programNumber == 1) loop1();
  else if(programNumber == 2) loop2();

void startProgram1() {
  // setup stuff for program 1

void loop1() {
  // stuff for program number 1

void startProgram2() {
  // setup stuff for program 2

void loop2() {
  // stuff for program number 2