Step Sequencer issue with first step

Hello! :slight_smile:

Currently I am working on a step sequencer with a touch screen and an audio shield. I am trying to create arrays to make my code a little bit simpler. For some reason though, the first step does not work, no matter what I do. Also the fourth one's LED is on all the time, as soon as I press on the step..

My code:

#include <Arduino.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Encoder.h>
#include <ILI9341_t3.h>
#include <font_Arial.h> // from ILI9341_t3
#include <XPT2046_Touchscreen.h>
#define CS_PIN 8
#define TFT_DC 9
#define TFT_CS 10
XPT2046_Touchscreen ts(CS_PIN);
#define TIRQ_PIN 2
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);

namespace modulo4
{
float map(float x, float in_min, float in_max, float out_min, float out_max)
{
 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
} // namespace modulo4
int width = 2;
constexpr int arrayLength = 257; // const kannst du während des programms initialisieren --> constexp liegt schon von Anfang an fest
float wave1ValuesUnscaled[arrayLength] = {0};
float wave2ValuesUnscaled[arrayLength] = {0};
int X, Y;
int Y_old;
int X_old;
boolean previous_is_touched;

typedef struct
{
 int x;
 int y;
} points_t;
AudioSynthWaveform *waveform = new AudioSynthWaveform[4];
AudioEffectEnvelope *envelope = new AudioEffectEnvelope[4];
int b1 = 0;
int b2 = 0;
int b3 = 0;
int b4 = 0;

float defaultAttackValue = {50};
float defaultDecayValue = {200};
float defaultSustainValue = {200};
float defaultReleaseValue = {200};
float attack[4] = {defaultAttackValue};
float decay[4] = {defaultDecayValue};
float sustain[4] = {defaultSustainValue};
float release[4] = {defaultReleaseValue};

/* int led3 = 3;
 int led4 = 4;
 int led5 = 5;
 int led6 = 6; */

int frequency1 = {500};
int frequency2 = {700};
int frequency3 = {900};
int frequency4 = (1100);

int stepLED[] = {3, 4, 5, 6};
float amplitude[] = {0.3};
int frequency[] = {frequency1, frequency2, frequency3, frequency4};
float mixerAmplitude = 0.1;


int StepState[] = {1};


unsigned long millisDelay = 400;

float yTop = 0;
float yBottom = 240;
int xLeft = 0;
int xRight = 320;

int xLeft256 = 0;
int xRight256 = 256;
int squareLength256 = 59;
int gap256 = 4;

float squareHeight = 14;
int squareLength = 73;
int radiusOfRoundCorner = 3;
int gap = 5;

char buttonNames[4][10] = { //First bracket indicates the amount of words
 "Clear",                // second bracket indicates the amount of maximal letters for one string
 "<----",
 "---->",
 "Waves"
};

int m_step = 0;
unsigned long m_interval = 300;
int m_STEPNUM = 4; // Amount of steps
unsigned long m_lastMillis;
int m_StepState[4] = {0};
int bpm = 120;
int previousA2 = 0; // previously sent poti values, to detect changes
int minBPM = 30;
int maxBPM = 220;
const int numReadings = 5; // Anzahl der Readings
int readings[numReadings]; // the readings from the analog input
int readIndex = 0;         // the index of the current reading
int total = 0;             // the running total
int average = 0;           // the average
int inputPin = A1;         // Analog input
int average_bpm = 0;
int average_bpm_alt = 0;
int16_t wave1ValuesScaled[arrayLength] = {0};
int16_t wave2ValuesScaled[arrayLength] = {0};

boolean wastouched = true;

void redrawButtons()
{
 tft.fillRoundRect(0, 224, 76, 14, 3, CL(0, 0, 0)); // Black background

 for (int i = 0; i < 4; ++i)
 { // DRAW THE FOUR SQUARES AT THE BOTTOM
   tft.fillRoundRect((gap + xLeft + ((gap + squareLength) * i)), (yBottom - squareHeight), squareLength, squareHeight, radiusOfRoundCorner, CL(250, 0, 0));
   tft.setCursor(26 + ((gap + squareLength) * i), 229);
   tft.print(buttonNames[i]);
 }
}

void ADSR(float att, float dec, float sus, float rel)
{ //HIGH and LOW are not boolean values.. they are integers, where HIGH = 1 and LOW = 0.

 // b1 = digitalRead(20);
 b2 = digitalRead(2);
 b3 = digitalRead(3);
 b4 = digitalRead(4);

 for (int i{0}; i < 4; ++i)
 {
   envelope[i].attack(attack[i]);
   envelope[i].decay(decay[i]);
   envelope[i].sustain(sustain[i]);
   envelope[i].release(release[i]);
 }

void clearDisplay()
{
 tft.fillScreen(ILI9341_BLACK);
 redrawButtons();
 tft.drawLine(0, 120, 320, 120, CL(255, 255, 255));
 tft.drawLine(0, 121, 320, 121, CL(255, 255, 255));
 tft.drawLine(0, 119, 320, 119, CL(255, 255, 255));
}

void clearArray()
{
 for (X = 0; X < arrayLength; X++)
 {
   wave1ValuesUnscaled[X] = 0;
 }
}

boolean pointInRect(int x, float y, float rectX, float rectY, float rectW, float rectH)
{
 boolean ret = false;
 if ((x >= rectX) && (x <= (rectX + rectW)) && (y >= rectY) && (y <= (rectY + rectH)))
 {
   ret = true;
 }
 return ret;
}

void setup()
{

 Serial.begin(38600); // 38600 symbols per second
 for (int i{0}; i < 4; ++i)
 {
   pinMode(stepLED[i], OUTPUT);
 }
 int stepButtonPin[] = {0, 1, 14, 15};

 for (int i{0}; i < 4; ++i)
 {
   pinMode(stepButtonPin[i], INPUT_PULLUP);
 }

 for (int i{0}; i < 4; ++i)
 {
   attack[i] = defaultAttackValue;
   decay[i] = defaultDecayValue;
   sustain[i] = defaultSustainValue;
   release[i] = defaultReleaseValue;
 }

 AudioMemory(20);
 sgtl5000_1.enable();
 sgtl5000_1.volume(0.5);
 for (int i{0}; i < 4; ++i)
 {
   mixer1.gain(i, mixerAmplitude);
 }
 for (int i{0}; i < 4; ++i)
 {
   waveform[i].begin(0); // WAVEFORM_SINE expands to 0
   waveform[i].amplitude(amplitude[i]);
   waveform[i].frequency(frequency[i]);
 }

 /* waveform1.begin(WAVEFORM_SINE); // WAVE 1
   waveform1.amplitude(amp1);
   waveform1.frequency(freq1);
   waveform2.begin(WAVEFORM_SINE); // WAVE 2
   waveform2.amplitude(amp2);
   waveform2.frequency(freq2);
   waveform3.begin(WAVEFORM_SINE); // WAVE 3
   waveform3.amplitude(amp3);
   waveform3.frequency(freq3);
   waveform4.begin(WAVEFORM_SINE); // WAVE 4
   waveform4.amplitude(amp4);
   waveform4.frequency(freq4); */

 //----------Touch---------//
 tft.begin();
 tft.setRotation(1);
 tft.fillScreen(ILI9341_BLACK);
 tft.drawLine(0, 0, 320, 120, CL(255, 255, 255));
 // tft.drawLine(0, 121, 320, 121, CL(255, 255, 255));
 // tft.drawLine(0, 119, 320, 119, CL(255, 255, 255));
 ts.begin();
 ts.setRotation(1);
 while (!Serial && (millis() <= 1000))
   ; // weiß nicht was das ist
 clearDisplay();
 redrawButtons();
}

void loop()
{

 /*int att = analogRead(A1);
   int dec = analogRead(A0);
   int rel = analogRead(A4);
   int sus = analogRead(A3); */

 static float bpm = {120}; // wird wegen static nur einmal initialisiert
 int n1 = analogRead(A1);

 boolean istouched = ts.touched();
 int X;
 float Y;
 if (istouched)
 {
   TS_Point p = ts.getPoint(); // point getter function
   X = map(p.x - 320, 3482, 0, 0, arrayLength - 1);

   if (X < 0)
   {
     X = 0;
   }

   Y = modulo4::map(p.y - 240.0, 3465.0, 0.0, 1.0, -1.0);
   wave1ValuesUnscaled[X] = Y;

   clearDisplay(); // Refreshing screen while drawing to remove values where one X has two Y points

   Y = map(Y, -1.0, 1.0, 240.0, 0.0);


   if (previous_is_touched)
   {
     for (int i = X_old; i < X;)
     {
       if (X_old <= X)
       {
         i++;
       }
       else
       {
         i--;
       }
       wave1ValuesUnscaled[i] = modulo4::map(i, X_old, X, wave1ValuesUnscaled[X_old], wave1ValuesUnscaled[X]);
     }
   }

   X_old = X;

   if (X > arrayLength)
   { // Avoiding glitchy values below X=257
     X = 257;
   }
 }
 previous_is_touched = istouched;

 int digitalReadValues[] = {digitalRead(0), digitalRead(1), digitalRead(14), digitalRead(15)};

 if ((millis() - m_lastMillis) > m_interval)
 {


   for (int i{0}; i < 4; ++i)
   {

     //   m_step = i;
     if (digitalReadValues[i] == LOW) // gedrückt
     {
       if (m_StepState[i] == 0)
       {
         m_StepState[i] = 1;
       }
       else
       {
         m_StepState[i] = 0;
       }
     }

     if ((m_step) == i)
     {
       digitalWrite(stepLED[i], m_StepState[i]);
       digitalWrite(stepLED[i] - 1, LOW);

       envelope[i].noteOn();
       waveform[i].amplitude(m_StepState[i]);
       waveform[i].frequency(frequency[i]);

       /* envelope1.noteOn();

           waveform1.amplitude(m_StepState[i]);
           waveform1.frequency(newEnc1); */
     }
   }

   if (m_step == m_STEPNUM)
   {
     m_step = 0;
   }
   m_step++;
   m_lastMillis = millis();
 }
}

An essential version of the sequencer part of the code:

unsigned long m_lastMillis;
unsigned long m_interval = 300;
int m_StepState[] = {0};
int m_step = 0;
int m_STEPNUM = 4;
int stepLED[] = {3, 4, 5, 6};

void setup() {
}

void loop() {
  int digitalReadValues[] = {
    
    digitalRead(0), digitalRead(1), digitalRead(14), digitalRead(15)};

  if ((millis() - m_lastMillis) > m_interval)
  {


    for (int i{0}; i < 4; ++i)
    {

      //   m_step = i;
      if (digitalReadValues[i] == LOW) // gedrückt
      {
        if (m_StepState[i] == 0)
        {
          m_StepState[i] = 1;

        }
        else
        {
          m_StepState[i] = 0;

        }
      }

      if ((m_step) == i)
      {
        digitalWrite(stepLED[i], m_StepState[i]);
        digitalWrite(stepLED[i] - 1, LOW);
      }

    }


    if (m_step == m_STEPNUM)
    {
      m_step = 0;
    }
    m_step++;

    m_lastMillis = millis();

  }
}

i think it might help you find your bug if you clearly describe what your code intends to do

it looks like it is simply toggling the value in m_stepState[] if the corresponding digital value is LOW

it looks like you want the LEDs to reflect the state of m_stepState[], but as soon as an LED is set, it is set LOW in the next timer iteration -- digitalWrite (stepLED -1, LOW). unclear what this does when stepLed[0] is 3 -- what is on digital pin 2 and the last stepLed pin is never set LOW
consider -- i don't believe this fixes your original problem
```
*unsigned long m_lastMillis;
unsigned long m_interval = 300;

#if 1
byte pinInp [] = { 0, 1, 14, 15 };
byte pinLed [] = { 3, 4, 5, 6 };

#else       // my hardware
byte pinInp [] = { A1, A2, A3 };
byte pinLed [] = { 10, 11, 12 };
#endif
#define N   sizeof(pinLed)

byte m_StepState [N] = {};

void setup() {
   for (unsigned i = 0; i < N; i++)  {
       pinMode (pinInp [i], INPUT_PULLUP);
       pinMode (pinLed [i], OUTPUT);
   }
}

void loop() {
   unsigned long msec = millis ();

if ((msec - m_lastMillis) > m_interval)  {
       m_lastMillis = msec;

for (unsigned i = 0; i < N; i++)  {
           if (LOW == digitalRead (pinInp [i]))
               m_StepState [i] = ! m_StepState [i];

digitalWrite (pinLed [i], m_StepState [i]);
       }
   }
}*
```

Hello gcjr! Thank you for your reply, you are right. The last LED was on all the time, exactly because of the reason, you just wrote. I tried to solve it this way:

unsigned long m_lastMillis;
unsigned long m_interval = 300;
int m_StepState[] = {1};
int m_step = 0;
int m_STEPNUM = 4;
int stepLED[] = {3, 4, 5, 6};

void setup() {
  for (int i{0}; i < 4; ++i)
  {
    pinMode(stepLED[i], OUTPUT);
  }
  /*  pinMode(led3, OUTPUT);
    pinMode(led4, OUTPUT);
    pinMode(led5, OUTPUT);
    pinMode(led6, OUTPUT); */

  int stepButtonPin[] = {0, 1, 14, 15};

  for (int i{0}; i < 4; ++i)
  {
    pinMode(stepButtonPin[i], INPUT_PULLUP);
  }
}

void loop() {
  int digitalReadValues[] = {

    digitalRead(0), digitalRead(1), digitalRead(14), digitalRead(15)
  };

  if ((millis() - m_lastMillis) > m_interval)
  {
    if (m_step == m_STEPNUM)
    {
      m_step = 0;
    }
    m_step++;

    m_lastMillis = millis();

    Serial.print("m_step:");
    Serial.print(m_step);
    Serial.println();

    for (int i{0}; i < 4; ++i)
    {

      if (m_step  == i + 1)
      {
        digitalWrite(stepLED[i], m_StepState[i]);
        digitalWrite(stepLED[i] - 1, LOW);
      }

      else if (m_step == 1)
      {
        digitalWrite(stepLED[3], LOW);

      }

      //   m_step = i;
      if (digitalReadValues[i] == LOW) // gedrückt
      {
        if (m_StepState[i] == 0)
        {
          m_StepState[i] = 1;
          Serial.print("Step ");
          Serial.print(i);
          Serial.print(": ");
          Serial.print(m_StepState[i]);
          Serial.print(" - ON");
          Serial.println();

        }
        else
        {
          m_StepState[i] = 0;
          Serial.print("Step ");
          Serial.print(i);
          Serial.print(": ");
          Serial.print(m_StepState[i]);
          Serial.print(" - OFF");
          Serial.println();

        }
      }
    }
  }
}

For some reason though, if I press my second button to turn the LED off, the m_step counter goes nuts and counts really fast in the terminal. Also if I press the 3rd button, it breaks out of the 4 steps loop and goes up higher..

i'm don't understand why you have various conditional tests: mstep = i+1, mstep == 1, mStepState ==0.
i showed you an approach that avoids those tests which are not working for you.

Your code works perfectly for turning the LEDs on and off, but I also have to have a sequencer, thats why I have the m_step++ part in my code. My plan is to have 4 LEDs where whenever the 3rd goes on the 2nd turns off, when the 4th goes on, the 3rd turns off etc. I need the knobs though, for additional control, to decide if I want to have the LED of a step on or off permanently.

matesi:
My plan is to have 4 LEDs where whenever the 3rd goes on the 2nd turns off, when the 4th goes on, the 3rd turns off etc.

i should have recognized this

i think this is closer to what you're trying to do. your for statement was very unconventional,

for (int i{0}; i < 4; ++i)
unsigned long m_lastMillis;
unsigned long m_interval = 300;

#if 0
byte pinInp  [] = { 0, 1, 14, 15 };
byte stepLED [] = { 3, 4, 5, 6 };

#else       // my hardware
byte pinInp  [] = { A1, A2, A3 };
byte stepLED [] = { 10, 11, 12 };
#endif
#define N   sizeof(stepLED)

byte m_StepState [N] = {};
byte digitalReadValues [N] = {};
unsigned  m_step = 0;
#define m_STEPNUM   N

enum { Off = HIGH, On = LOW, };

void setup() {
    for (unsigned i = 0; i < N; i++)  {
        pinMode (pinInp [i], INPUT_PULLUP);
        pinMode (stepLED [i], OUTPUT);
    }
}

void loop() {
    for (unsigned i = 0; i < N; i++)
        digitalReadValues [i]  = digitalRead (pinInp [i]);

    if ((millis() - m_lastMillis) > m_interval)
    {
        if (++m_step == m_STEPNUM)
        {
            m_step = 0;
        }

        m_lastMillis = millis();
        Serial.print("m_step:");
        Serial.print(m_step);
        Serial.println();

        for (unsigned i = 0; i < m_STEPNUM; i++)
        {
            if (m_step == i)
                digitalWrite(stepLED[i], m_StepState[i]);
            else
                digitalWrite(stepLED[i], Off);

            //   m_step = i;
            if (digitalReadValues[i] == LOW) // gedrückt
            {
                if (m_StepState[i] == 0)
                {
                    m_StepState[i] = 1;
                    Serial.print("Step ");
                    Serial.print(i);
                    Serial.print(": ");
                    Serial.print(m_StepState[i]);
                    Serial.print(" - ON");
                    Serial.println();
                }

                else
                {
                    m_StepState[i] = 0;
                    Serial.print("Step ");
                    Serial.print(i);
                    Serial.print(": ");
                    Serial.print(m_StepState[i]);
                    Serial.print(" - OFF");
                    Serial.println();
                }

            }

        }

    }
}

With this one, none of the LEDs work. Also the m_step counter only goes from 0 to 2.

sorry, the #if is using my hardware. change it to #if 1

The LEDs work now, they light up in a weird order though, not in the 1,2,3,4 sequence. It's also difficult to me, to entirely understand how the syntax you've written works, especially with the #if 1 or #else.

the c-preprocessor handles lines beginning with "#". it's useful for handling different hardware among many other configuration issues.

unless you have a specific example about syntax, suggest you study to the code. the Elements of Programming Style is one of the best books i learned to program from.

Alright, thank you! Which book do you mean? The hyperlink directs me to c preprocessor.

elements of programming style

Thank you!
I don't quite understand, why in this code, my first LED wont light up and why the 4th one is on all the time. I wrote the else if statement, to avoid the 4th one being on all the time, but it doesn't seem to work.

unsigned long m_lastMillis;
unsigned long m_interval = 300;
int m_StepState[] = {1};
int m_step = 0;
int m_STEPNUM = 4;
int stepLED[] = {3, 4, 5, 6};

void setup() {
  for (int i{0}; i < 4; ++i)
  {
    pinMode(stepLED[i], OUTPUT);
  }

  int stepButtonPin[] = {0, 1, 14, 15};

  for (int i{0}; i < 4; ++i)
  {
    pinMode(stepButtonPin[i], INPUT_PULLUP);
  }
}

void loop() {
  int digitalReadValues[] = {

    digitalRead(0), digitalRead(1), digitalRead(14), digitalRead(15)
  };

  if ((millis() - m_lastMillis) > m_interval)
  {
    m_lastMillis = millis();
    if (m_step == m_STEPNUM)
    {
      m_step = 0;
    }
    m_step++;


    for (int i{0}; i < 4; ++i) {

      Serial.print("m_step:");
      Serial.print(m_step);
      Serial.println();
      Serial.println();
      Serial.print("i+1:");
      Serial.print(i + 1);
      Serial.println();

      if (m_step == i + 1)
      {
        digitalWrite(stepLED[i], m_StepState[i]);
        digitalWrite(stepLED[i] - 1, LOW);
      }
      else if (m_step == 1)
      {
        digitalWrite(stepLED[3], LOW);
      }
      if (digitalReadValues[i] == LOW) // gedrückt
      {
        if (m_StepState[i] == 0)
        {
          m_StepState[i] = 1;
          Serial.print("Step ");
          Serial.print(i);
          Serial.print(": ");
          Serial.print(m_StepState[i]);
          Serial.print(" - ON");
          Serial.println();

        }
        else
        {
          m_StepState[i] = 0;
          Serial.print("Step ");
          Serial.print(i);
          Serial.print(": ");
          Serial.print(m_StepState[i]);
          Serial.print(" - OFF");
          Serial.println();

        }
      }
    }
  }
}

i don't see a conditional check for m_step == 0

Hello!

Here is my new code with conditional check for m_step == 0:

unsigned long m_lastMillis;
unsigned long m_interval = 200;
int m_StepState[] = {1};
int m_step = 0;
int m_STEPNUM = 4;
int stepLED[] = {3, 4, 5, 6};

int m_Step1State = 1;
int m_Step2State = 1;
int m_Step3State = 1;
int m_Step4State = 1;



void setup() {
  int stepButtonPin[] = {0, 1, 14, 15};

  for (int i{0}; i < 4; ++i)
  {
    pinMode(stepLED[i], OUTPUT);
    pinMode(stepButtonPin[i], INPUT_PULLUP);
  }

}

void loop() {
  int digitalReadValues[] = {digitalRead(0), digitalRead(1), digitalRead(14), digitalRead(15)};


  if ((millis() - m_lastMillis) > m_interval)
  {
    m_lastMillis = millis();
    m_step++;
    if (m_step == m_STEPNUM)
    {
      m_step = 0;
    }
  }

  for (int i{0}; i < 4; ++i)
  {
    if (m_step == 0)
    {
      digitalWrite(stepLED[0], m_StepState[0]);
      digitalWrite(stepLED[3], LOW);
    }
    else if (m_step == i)
    {
      digitalWrite(stepLED[i], m_StepState[i]);
      digitalWrite(stepLED[i] - 1, LOW);
    }
  }

  for (int j{0}; j < 4; ++j)
  {
    if (digitalReadValues[j] == LOW)
    {
      if (m_StepState[j] == 0)
      {
        m_StepState[j] = 1;
      }
      else
      {
        m_StepState[j] = 0;
      }
    }
  }

Whenever I run it, the sequencer works fine, but if I press on some of the buttons, it results in undefined behavior and the m_step seems to "break out" of the loop and goes towards infinity.. Does anyone have an idea? :confused:

when i run your program, i can disable (?) all the LEDs by holding the corresponding button down as it sequences thru. this somewhat difficult but i can get all the LEDs to be off. but this is apparently how the code is intended to work

instead of a conditional test, you can m_StepState[j] = ! m_StepState [j]; "extra code" makes it harder to read and increases the chance of a bug.

i don't know why you added a second loop using "j". (extra code)

don't know why you don't update digitalReadValues [] inside your loop, you only check the value for the i value in the loop. (again extra code) (extra code)

you continue to use for (int i{0}; i < 4; ++i). int i{0} may compile but is not correct

i prefer to test code rather than trust my professional eyeball to see bugs in code, which means i need to modify your code each time rather than simply change the #if/else to switch to my hardware. i'm not likely to go thru the trouble again. and seeing that it seems to work, there should be no need.

consider the following. it does what you

unsigned long m_lastMillis;
unsigned long m_interval = 200;

#if 0
int m_StepState [] = {1};
int m_STEPNUM = 4;
int stepLED [] = {3, 4, 5, 6};
byte stepButtonPin [] = {0, 1, 14, 15};

#else
byte stepLED [] = { 10, 11, 12 };
byte stepButtonPin [] = { A1, A2, A2 };
# define m_STEPNUM  sizeof (stepLED)

int m_StepState [m_STEPNUM] = {1};
#endif

unsigned m_step = 0;

void setup () {
    for (unsigned i = 0; i < m_STEPNUM; ++i)
    {
        pinMode (stepLED [i], OUTPUT);
        pinMode (stepButtonPin [i], INPUT_PULLUP);
    }
}

void loop ()
{
    if ( (millis () - m_lastMillis) < m_interval)
        return;

    m_lastMillis = millis ();

    digitalWrite (stepLED [m_step], LOW);

    if (++m_step == m_STEPNUM)
        m_step = 0;

    if (digitalRead (stepButtonPin [m_step]))
        m_StepState [m_step] = ! m_StepState [m_step];

    digitalWrite (stepLED [0], m_StepState [0]);
}

Hello! Currently, I am working on a step sequencer and I would like to write my code with arrays, to make it less redundant. I can't really figure out how to turn off the LED of the last step, as the sequencer moves on to the 1st step again.

My failed attempt:

  for (int i{0}; i < 4; ++i)
  {
     int j = i - 1;
     if (m_step == 1)
    {
      digitalWrite(stepLED[0], m_StepState[0]);
      digitalWrite(stepLED[3], LOW);
    }
    else if (m_step == i + 1)
    {
      digitalWrite(stepLED[i], m_StepState[i]);
      digitalWrite(stepLED[i - 1], LOW);
  }  
   if (m_step == i)
    {
     if (j < 0)
      {
        j = 3;
        } 
      digitalWrite(stepLED[i], m_StepState[i]);
      digitalWrite(stepLED[j], LOW);
    }
  }

Strange way of writing code:   for (int i{0}; i < 4; ++i)

Why not:   for (int i=0; i < 4; ++i) ?

Also....Learn to use comments to tell what the lines in the code are supposed to do.
To make things a lot better, post the entire code if You want replies.

Why start a new thread. You have an answer in the other one.

Cross posted Step Sequencer issue with first step - #16 by matesi - Programming Questions - Arduino Forum