How do I create a sequence selection Button

Hello, ladies and gentlemen. My hope is to create a script that selects a sequence of instructions per button press and after a set amount of time executes that program. this allows me time to scroll through the sequences. the aim of each sequence is to set a different pattern on a flasher via pulses.

If it's possible I'd like 4 or more selectable sequences to allow me to do other types of flasher.

Further to this, I will be adding another relay that selects between ground and VIN but that will come when I have the basic program working as intended.

The states in the code are LEDs to show which sequence I have selected

Here is what I have so far:

int relayPin = 5; 
int buttonPin = 11;
int oldButtonState = HIGH;
int x = 0;
int state1 = A0;
int state2 = A1;
int state3 = A2;
int state4 = A3;

void setup() {
// put your setup code here, to run once:
 pinMode(relayPin, OUTPUT);
 pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
// Get the current state of the button
  int newButtonState = digitalRead(buttonPin);

  // Has the button gone high since we last read it?
  if (newButtonState == HIGH && oldButtonState == LOW) {

    if (x == 0) {
      // Sequence 1
digitalWrite(state1, HIGH);
delay(100);
digitalWrite(relayPin, HIGH);
delay(5000);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(state1, LOW);
delay(100);
      x = 1;
} else {
      // Sequence 2
digitalWrite(state2, HIGH);
delay(100);
digitalWrite(relayPin, HIGH);
delay(5000);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(state2, LOW);
delay(100);
      x = 0;
    }
  }

  // Store the button's state so we can tell if it's changed next time round
  oldButtonState = newButtonState;
}

I'm very new to coding so I'm rather lost at this point, Thanks in advance for any help you can give :).

Wrote this for a single button speed selector, steps with each button press and takes the current speed if paused for 1.5 seconds, might give you some ideas, sorry, no comments but I will if you need them.

uint32_t tStart, timeStart, tEnd;// = 2000UL;
int speeds [] = {0, 50, 100, 200, 400};
int speed;
const byte dbTime = 15, btn = 4, ledPin = 13;
bool btnState = false, bState = true, oldBstate = true,
     timing = false, speedSet = false;
byte cntr;

void setup()
{
  Serial.begin(115200);
  pinMode(btn, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
// debounce-----------------------------
  if (digitalRead(btn) != btnState) // they are different!
  {
    btnState ^= 1;                  // make them equal
    timeStart = millis();           // restart timer
  }
  if (millis() - timeStart > dbTime)  // if not changed for dbTime,
     bState = btnState; // btnState is valid, use it
// end debounce-------------------------
  
  if(!timing && !bState && oldBstate)
  {
    tStart = millis();
    tEnd = 1500UL;
    cntr = 0;
    timing = true;
    speedSet = true;
    
  }

  
  if(timing && !bState && oldBstate)
  {
    if(++cntr > 5)
      cntr = 1;
    tStart = millis();
    Serial.println(speeds[cntr - 1]);
    oldBstate = bState;
  }

  if(millis() - tStart > tEnd)
  {
    timing = false;    
    if(speedSet)
    {
      speed = speeds[cntr - 1];
      if(!bState)
        speed = 0;
      Serial.print("Speed set to ");
      Serial.println(speed);
      Serial.println("Press button to change");
      speedSet = false;
    }
  }
  digitalWrite(ledPin,timing);
  oldBstate = bState;

   
}

mike2156:
Hello, ladies and gentlemen. My hope is to create a script that selects a sequence of instructions

You are not going about your sequence in an economical way. If you store the intervals in an array - for example

int myIntervals[] = [100, 5000, 200, 200];
byte numIntervals = 4;
byte relayState = HiGH;
byte intervalPosition = 0;

you could do the whole thing in 5 lines of code

void loop() {
   if (intervalPosition < numIntervals) {
      digitalWrite(relayPin, relayState);
      relayState = ! relayState;
      delay(myIntervals[intervalPosition];
      intervalPosition ++;
   }
}

However it would be much better not to use delay() at all and use millis() to manage the timing as in @edgemoron’s code and in the demo Several Things at a Time

If you use delay() you will have to wait for the delay() to complete before you can detect the next button press.

…R

Awesome, I'll figure out how to implement the arrays tomorrow, next I need to figure out how to set up 4 of these sequences based on the multiple speed selector script above

You can create a 2 dimensional array - an array of arrays.

...R

Ok so after much typing and pain I’ve got this:

int buttonPins = 10; //Start Program
int buttonPin = 11;  //Program Selector
int relayPin = 5;
int myIntervalsPA3[] = {100, 5000, 200, 200, 200, 200,};
int myIntervalsPA4[] = {100, 5000, 200, 200, 200, 200, 200,};
int myIntervalsPA5[] = {100, 5000, 200, 200, 200, 200, 200, 200, 200,};
int myIntervalsPA6[] = {100, 5000, 200, 200, 200, 200, 200, 200, 200, 200,};
byte numIntervalspa3 = 6;
byte numIntervalspa4 = 7;
byte numIntervalspa5 = 9;
byte numIntervalspa6 = 10;
byte relayState = HIGH;
byte intervalPosition = 0;
int ledPin1 = A0;
int ledPin2 = A1;
int ledPin3 = A2;
int ledPin4 = A3;
int val = 0; // variable to read Program Selector value
int ledSequence = 0; // variable to hold current LED sequence
int sequence = 0; // variable to hold current program sequence

int start = 0;
int startpush = 0;
void setup()
{
    pinMode(ledPin1, OUTPUT); //set each LED pin to output
    pinMode(ledPin2, OUTPUT);
    pinMode(ledPin3, OUTPUT);
    pinMode(ledPin4, OUTPUT);
    pinMode(buttonPin, INPUT_PULLUP); //button connected to Vcc when not pressed
    pinMode(relayPin, OUTPUT);
    pinMode(buttonPins, INPUT_PULLUP);
  }
void loop(){
  start = digitalRead(buttonPins);
   val = digitalRead(buttonPin);
  if(start == LOW){
    startpush = 1;
  delay(300);
  }
  if (val == HIGH)
  {
    if (sequence, ledSequence == 4) // if sequence is at 4 already, make it 1 again
    {
      sequence, ledSequence = 0;
    } else
    {
      sequence++; // otherwise go to the next sequence
      ledSequence++;
    }
    delay(300);  // we need this here to ensure that only one button press is registered
    // otherwise sequence is very quickly incremented and the circuit doesn't work
    // if you don't understand what I mean, remove this delay and try it...
  }
   switch (ledSequence)
   {
case 1:
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW);
    break;
    return;
case 2:
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW);
    break;
    return;

 case 3:
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin4, LOW);
    break;
    return;
 
case 4:
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, HIGH);
    break;
    return;
  }
 if (startpush = 1){ 
  switch (sequence)
  {
    case 1:
    if (intervalPosition < numIntervalspa3) {
    digitalWrite(relayPin, relayState);
      relayState = ! relayState;
      delay(myIntervalsPA3[intervalPosition]);
            intervalPosition ++;
    break;
    return;
     }
    case 2:
    if (intervalPosition < numIntervalspa4) {
    digitalWrite(relayPin, relayState);
      relayState = ! relayState;
      delay(myIntervalsPA4[intervalPosition]);
            intervalPosition ++;
    break;
    return;
    }
    case 3:
    if (intervalPosition < numIntervalspa5) {
    digitalWrite(relayPin, relayState);
      relayState = ! relayState;
      delay(myIntervalsPA5[intervalPosition]);
            intervalPosition ++;
    break;
    return;
    }
    case 4:
    if (intervalPosition < numIntervalspa6) {
      digitalWrite(relayPin, relayState);
      relayState = ! relayState;
      delay(myIntervalsPA6[intervalPosition]);
            intervalPosition ++;
     break;
     return;
     }
    }
   }
 }

However, the select button starts the sequence where I’d like the start button to do that, once the first sequence is finished it doesn’t reset so that I can run another sequence. only sequence 1 does anything, the LED’s do work as expected though i do need to figure out how to debounce my switches.

Read this thread. I covered this quite extensively with someone else.

Timing trouble with millis() for LED control

ok, so I’m still having trouble with this when I press the start button it doesn’t run the array sequences correctly.

bool buttonState; 
bool lastState;
bool toggle = false; // variable for first status
const int  btPin = 10;    // Start
const int  btPinsel = 11;    // Select
int relayPin = 5;
int relayPin2 = 6;
int myIntervalsPA3[] = {5000, 200, 200, 200, 200,};
int myIntervalsPA4[] = {5000, 200, 200, 200, 200, 200,};
int myIntervalsPA5[] = {5000, 200, 200, 200, 200, 200, 200, 200,};
int myIntervalsPA6[] = {5000, 200, 200, 200, 200, 200, 200, 200, 200,};
int ledPin1 = A0;
int ledPin2 = A1;
int ledPin5 = A4;
int ledSequence = 0; // variable to hold current LED sequence
int sequence = 0; // variable to hold current program sequence
int select;
byte numIntervalspa3 = 6;
byte numIntervalspa4 = 7;
byte numIntervalspa5 = 9;
byte numIntervalspa6 = 10;
byte relayState = HIGH;
byte intervalPositionPA3 = 0;
byte intervalPositionPA4 = 0;
byte intervalPositionPA5 = 0;
byte intervalPositionPA6 = 0;

void setup()
{
    pinMode(btPin, INPUT_PULLUP);
    pinMode(btPinsel, INPUT_PULLUP);    
    pinMode(ledPin1, OUTPUT); //set each LED pin to output
    pinMode(ledPin2, OUTPUT);
    pinMode(ledPin5, OUTPUT);
    pinMode(relayPin, OUTPUT);
    Serial.begin(9600);
  }
void loop(){
select = digitalRead(btPinsel);
if (select == HIGH){
 if (sequence, ledSequence == 3) // if sequence is at 4 already, make it 1 again
    {
      sequence, ledSequence = 0;
    } else
    {
      sequence++; // otherwise go to the next sequence
      ledSequence++;
    }
    delay(500);  // we need this here to ensure that only one button press is registered
    // otherwise sequence is very quickly incremented and the circuit doesn't work
    // if you don't understand what I mean, remove this delay and try it...
  {
    switch (ledSequence)
     {
case 1:
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, LOW);
    break;
case 2:
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, HIGH);
    break;
  }
 }
}
if (digitalRead(btPin) == LOW) {
  toggle = !toggle;
  while (digitalRead(btPin) == LOW);
}
 switch (toggle)
 {
  case 1:
    digitalWrite(ledPin5, HIGH); 
    switch (sequence)
  {
   case 1:
    if (intervalPositionPA3 < numIntervalspa3) {
    digitalWrite(relayPin, relayState);
      relayState = ! relayState;
      delay(myIntervalsPA3[intervalPositionPA3]);
            intervalPositionPA3 ++;
    }
     if (intervalPositionPA4 < numIntervalspa4) {
    digitalWrite(relayPin2, relayState);
      relayState = ! relayState;
      delay(myIntervalsPA4[intervalPositionPA4]);
            intervalPositionPA4 ++;
        break; 
        }
        case 2:
       if (intervalPositionPA5 < numIntervalspa5) {
    digitalWrite(relayPin, relayState);
      relayState = ! relayState;
      delay(myIntervalsPA5[intervalPositionPA5]);
            intervalPositionPA5 ++;
       }
       if (intervalPositionPA6 < numIntervalspa6) {
      digitalWrite(relayPin2, relayState);
      relayState = ! relayState;
      delay(myIntervalsPA6[intervalPositionPA6]);
            intervalPositionPA6 ++;
        break;
    }
    }
    default:
    {
      digitalWrite(ledPin5, LOW);
      return;
    }
  }
}

At this point I’m totally lost :frowning:

Please use the AutoFormat tool to indent your code consistently and post it again. At the moment it is too difficult to see which parts belong together.

...R

Oh, that’s a nifty feature I glossed over, thanks for that. Here’s the properly formatted code:

bool toggle = false; // variable for first status
const int  btPin = 10;    // Start
const int  btPinsel = 11;    // Select
int relayPin = 5;
int relayPin2 = 6;
int myIntervalsPA3[] = {5000, 200, 200, 200, 200,};
int myIntervalsPA4[] = {5000, 200, 200, 200, 200, 200,};
int myIntervalsPA5[] = {5000, 200, 200, 200, 200, 200, 200, 200,};
int myIntervalsPA6[] = {5000, 200, 200, 200, 200, 200, 200, 200, 200,};
int ledPin1 = A0;
int ledPin2 = A1;
int ledPin5 = A4;
int ledSequence = 0; // variable to hold current LED sequence
int sequence = 0; // variable to hold current program sequence
int select;
byte numIntervalspa3 = 6;
byte numIntervalspa4 = 7;
byte numIntervalspa5 = 9;
byte numIntervalspa6 = 10;
byte relayState = HIGH;
byte intervalPositionPA3 = 0;
byte intervalPositionPA4 = 0;
byte intervalPositionPA5 = 0;
byte intervalPositionPA6 = 0;

void setup()
{
  pinMode(btPin, INPUT_PULLUP);
  pinMode(btPinsel, INPUT_PULLUP);
  pinMode(ledPin1, OUTPUT); //set each LED pin to output
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(relayPin, OUTPUT);
  Serial.begin(9600);
}
void loop() {
  select = digitalRead(btPinsel);
  if (select == HIGH) {
    if (sequence, ledSequence == 3) // if sequence is at 4 already, make it 1 again
    {
      sequence, ledSequence = 0;
    } else
    {
      sequence++; // otherwise go to the next sequence
      ledSequence++;
    }
    delay(500);  // we need this here to ensure that only one button press is registered
    // otherwise sequence is very quickly incremented and the circuit doesn't work
    // if you don't understand what I mean, remove this delay and try it...
    {
      switch (ledSequence)
      {
        case 1:
          digitalWrite(ledPin1, HIGH);
          digitalWrite(ledPin2, LOW);
          break;
        case 2:
          digitalWrite(ledPin1, LOW);
          digitalWrite(ledPin2, HIGH);
          break;
      }
    }
  }
  if (digitalRead(btPin) == LOW) {
    toggle = !toggle;
    while (digitalRead(btPin) == LOW);
  }
  switch (toggle)
  {
    case 1:
      digitalWrite(ledPin5, HIGH);
      switch (sequence)
      {
        case 1:
          if (intervalPositionPA3 < numIntervalspa3) {
            digitalWrite(relayPin, relayState);
            relayState = ! relayState;
            delay(myIntervalsPA3[intervalPositionPA3]);
            intervalPositionPA3 ++;
          }
          if (intervalPositionPA4 < numIntervalspa4) {
            digitalWrite(relayPin2, relayState);
            relayState = ! relayState;
            delay(myIntervalsPA4[intervalPositionPA4]);
            intervalPositionPA4 ++;
            break;
          }
        case 2:
          if (intervalPositionPA5 < numIntervalspa5) {
            digitalWrite(relayPin, relayState);
            relayState = ! relayState;
            delay(myIntervalsPA5[intervalPositionPA5]);
            intervalPositionPA5 ++;
          }
          if (intervalPositionPA6 < numIntervalspa6) {
            digitalWrite(relayPin2, relayState);
            relayState = ! relayState;
            delay(myIntervalsPA6[intervalPositionPA6]);
            intervalPositionPA6 ++;
            break;
          }
      }
    default:
      {
        digitalWrite(ledPin5, LOW);
        return;
      }
  }
}

I am not an expert. Is this valid C code, and what does it do?

    if (sequence, ledSequence == 3)

...R

if (sequence, ledSequence == 3)
What do you think is happening here?

.

My hope is that it reads the 2 switch case statements and makes sure they are only ever 1 or 2.
Like I say I'm a huge novice trying to create a program based on my very limited knowledge and advice from you guys here. :confused:

The function of the circuit is to pulse the negative line a set number of times depending on the flasher (Signal 911 XT3 or XT4) I have hooked up so that I can auto sequence them to the correct setting, I want the 3 LED'S I have hooked up (2 White and one blue) to indicate which pulse sequence I have selected (the 2 or eventually more White LED's (ledPins 1 & 2)) and to indicate that I have pressed the start button (the blue LED(ledPin 5))

mike2156:
My hope is that it reads the 2 switch case statements and makes sure they are only ever 1 or 2.

That statement does not make any sense because the line I quoted (line 40) has nothing to do with SWITCH CASE.

The proper structure of an if statement is

if (sequence == 3 or ledSequence == 3)

if that is what you mean.

...R

I got the code running after scrapping the arrays and just going with a large list of digitalWrites.

bool toggle = false; // variable for first status
const int  btPin = 10;    // Start
const int  btPinsel = 11;    // Select
int relayPin = 5;
int relayPin2 = 3;
int myIntervalsPA3[] = {5000, 200, 200, 200, 200,};
int myIntervalsPA4[] = {5000, 200, 200, 200, 200, 200,};
int myIntervalsPA5[] = {5000, 200, 200, 200, 200, 200, 200, 200,};
int myIntervalsPA6[] = {5000, 200, 200, 200, 200, 200, 200, 200, 200,};
int ledPin1 = A0;
int ledPin2 = A1;
int ledPin5 = A4;
int ledSequence = 0; // variable to hold current LED sequence
int sequence = 0; // variable to hold current program sequence
int select;
byte numIntervalspa3 = 6;
byte numIntervalspa4 = 7;
byte numIntervalspa5 = 9;
byte numIntervalspa6 = 10;
byte relayState = HIGH;
byte intervalPositionPA3 = 0;
byte intervalPositionPA4 = 0;
byte intervalPositionPA5 = 0;
byte intervalPositionPA6 = 0;

void setup()
{
  pinMode(btPin, INPUT_PULLUP);
  pinMode(btPinsel, INPUT_PULLUP);
  pinMode(ledPin1, OUTPUT); //set each LED pin to output
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(relayPin2, OUTPUT);
  Serial.begin(9600);
}
void(* resetFunc) (void) = 0; //declare reset function @ address 0
void loop() {
  select = digitalRead(btPinsel);
  if (select == HIGH) {
    if (sequence, ledSequence == 3) // if sequence is at 4 already, make it 1 again
    {
      sequence, ledSequence = 0;
    } else
    {
      sequence++; // otherwise go to the next sequence
      ledSequence++;
    }
    delay(500);  // we need this here to ensure that only one button press is registered
    // otherwise sequence is very quickly incremented and the circuit doesn't work
    // if you don't understand what I mean, remove this delay and try it...
    {
      switch (ledSequence)
      {
        case 1:
          digitalWrite(ledPin1, HIGH);
          digitalWrite(ledPin2, LOW);
          break;
        case 2:
          digitalWrite(ledPin1, LOW);
          digitalWrite(ledPin2, HIGH);
          break;
      }
    }
  }
  if (digitalRead(btPin) == LOW) {
    toggle = !toggle;
    delay(200);
  }
  if (toggle == true) {
    digitalWrite(ledPin5, HIGH);
  }
  else
  {
    digitalWrite(ledPin5, LOW);
  }
  switch (toggle)
  {
    case 1:
      switch (sequence)
      {
        case 1:
          delay(200);
          digitalWrite(relayPin, HIGH);
          digitalWrite(relayPin2, HIGH);
          delay(5000);
          digitalWrite(relayPin, LOW);
          digitalWrite(relayPin2, LOW);
          delay(200);
          digitalWrite(relayPin, HIGH);
          digitalWrite(relayPin2, HIGH);
          delay(200);
          digitalWrite(relayPin, LOW);
          digitalWrite(relayPin2, LOW);
          delay(200);
          digitalWrite(relayPin, HIGH);
          digitalWrite(relayPin2, HIGH);
          delay(200);
          digitalWrite(relayPin, LOW);
          digitalWrite(relayPin2, LOW);
          delay(200);
          digitalWrite(relayPin, HIGH);
          digitalWrite(relayPin2, HIGH);
          delay(200);
          digitalWrite(relayPin, LOW);
          digitalWrite(relayPin2, LOW);
          delay(200);
          digitalWrite(relayPin, HIGH);
          digitalWrite(relayPin2, HIGH);
          delay(200);
          digitalWrite(relayPin, LOW);
          digitalWrite(relayPin2, LOW);
          delay(200);
          digitalWrite(relayPin2, HIGH);
          delay(200);
          digitalWrite(relayPin2, LOW);
          delay(200);
          digitalWrite(ledPin1, LOW);
          resetFunc();
          break;
        case 2:
          delay(200);
          digitalWrite(relayPin, HIGH);
          digitalWrite(relayPin2, HIGH);
          delay(5000);
          digitalWrite(relayPin, LOW);
          digitalWrite(relayPin2, LOW);
          delay(200);
          digitalWrite(relayPin, HIGH);
          digitalWrite(relayPin2, HIGH);
          delay(200);
          digitalWrite(relayPin, LOW);
          digitalWrite(relayPin2, LOW);
          delay(200);
          digitalWrite(relayPin, HIGH);
          digitalWrite(relayPin2, HIGH);
          delay(200);
          digitalWrite(relayPin, LOW);
          digitalWrite(relayPin2, LOW);
          delay(200);
          digitalWrite(relayPin, HIGH);
          digitalWrite(relayPin2, HIGH);
          delay(200);
          digitalWrite(relayPin, LOW);
          digitalWrite(relayPin2, LOW);
          delay(200);
          digitalWrite(relayPin, HIGH);
          digitalWrite(relayPin2, HIGH);
          delay(200);
          digitalWrite(relayPin, LOW);
          digitalWrite(relayPin2, LOW);
          delay(200);
          digitalWrite(relayPin, HIGH);
          digitalWrite(relayPin2, HIGH);
          delay(200);
          digitalWrite(relayPin, LOW);
          digitalWrite(relayPin2, LOW);
          delay(200);
          digitalWrite(relayPin, HIGH);
          digitalWrite(relayPin2, HIGH);
          delay(200);
          digitalWrite(relayPin, LOW);
          digitalWrite(relayPin2, LOW);
          delay(200);
          digitalWrite(relayPin2, HIGH);
          delay(200);
          digitalWrite(relayPin2, LOW);
          delay(200);
          digitalWrite(ledPin2, LOW);
          resetFunc();
          break;
      }
    default:
      {
        break;
      }
  }
}

Thanks for your help guys and girls.

Robin2:
That statement does not make any sense because the line I quoted (line 40) has nothing to do with SWITCH CASE.

The proper structure of an if statement is

if (sequence == 3 or ledSequence == 3)

if that is what you mean.

...R

The purpose of this section is to increment the 2 Integers (sequence and ledSequence) together while making sure they never go above 2.

 select = digitalRead(btPinsel);
  if (select == HIGH) {
    if (sequence, ledSequence == 3) // if sequence is at 4 already, make it 1 again
    {
      sequence, ledSequence = 0;
    } else
    {
      sequence++; // otherwise go to the next sequence
      ledSequence++;
    }

Then this switch case statement uses the ledSequence value to figure out which case it needs to run.

 switch (ledSequence)
      {
        case 1:
          digitalWrite(ledPin1, HIGH);
          digitalWrite(ledPin2, LOW);
          break;
        case 2:
          digitalWrite(ledPin1, LOW);
          digitalWrite(ledPin2, HIGH);
          break;
      }

and likewise with the main switch case but it uses the integer from sequence and waits for the output of toggle to start.

for some reason, the syntax I used in (sequence, ledSequence == 3) seems to work and saves a small amount of typing.

"for some reason, the syntax I used in (sequence, ledSequence == 3) seems to work and saves a small amount of typing"

Suggest you don't invent your own syntax.

https://www.arduino.cc/en/Reference/HomePage

https://www.arduino.cc/en/Reference/Else

https://www.arduino.cc/en/Reference/Boolean

.

larryd:
"For some reason, the syntax I used in (sequence, ledSequence == 3) seems to work and saves a small amount of typing"

Suggest you don't invent your own syntax.

Arduino Reference - Arduino Reference

else - Arduino Reference

&& - Arduino Reference

.

And why not? The entire ICT industry was in part made a reality by people who made their own Syntax. Besides, it's not causing any unnecessary stress on the arduino or causing any loops or anything odd to happen. It's perfectly fine.

Okay, go and invent you own syntax, you reap the benefits.

Don't be surprise if people here give your questions a wide berth.
.

mike2156:
and saves a small amount of typing.

That is the worst possible reason for doing anything when programming. Programs should be written so there is nothing ambiguous about them.

seems to work

What testing have you done to prove to yourself that it does in fact work and to identify the cases where it does not work - which is just as important to know.

...R