TPIC6B595 Shift Registers Controlling Multiple Steppers

Leo,
You are my Superman, thanks a million times.
Please forgive me for not explaining my project. I took it for granted that you knew what I was doing from another tread I posted. Please take a look (scroll down) at this art work in the following video.

I made a replica of this with 3D printed gears instead of laser cut wooden gears used by the artist and I wanted to motorize it. I couldn't find anyone to design and laser cut the gears and the 3D printing approach failed. The gear passes were too large, no smooth movement and there were alignment problems. So after multiple attempts and throwing away hundreds of 3D printed gears I had an idea. Since the patterns are made only by the white part of the rotating gears why not just 3D print half circles (no gears) in white with a shaft and attached them to a stepper. Now my problem was controlling 41 steppers and that's where I thought of using one of your boards. Please note that in the video, when the gears are turned, you get an interesting pattern only at certain positions. That's why I thought of an array of prefixed positions. And to make things more interesting I'd throw in a PIR sensor to sense someone in front of this hanging on the wall, then a random index number which will point to one of these prefixed positions. Please forgive my long thread but I owed it to you and I hope it clears up some doubts.

Back to your code, it works fine. I made a couple of changes which need your approval.
first I commented out tis part:

void loop() {
  switch (sequence) {
    case 0: // load random positions for each motor into the new position array
      //   for (byte i = 0; i < motors; i++) {
      //     newPos[i] = random(-500, 500); // about a quarter turn max, right or left from start position
      //      }
      // eepromSave(); // could call eeprom write function here
      sequence = 1; // go to next case
      prevMillis = millis(); // but first mark the time
      break;

Since I need all steppers to go to the same random position. works fine but is it ok ?

then I defined an array of prefixed TargetPositions[500, 850, 1020, etc.] and changed your code to generate a random number from 0 to n (number of the values in TargetPos. This random number points to / picks one of those positions as the new position from the array.

 case 1: // move all motors the same random direction/steps
      if (millis() - prevMillis > 8000) { // after 8 seconds

        //      randNumber = random(-1024, 1024); // max half a turn
        
        randNumber = random(0, 7);  // to be decided , just an example

        for (byte i = 0; i < motors; i++) {
          // newPos[i] = randNumber; // all motors the same (random) new position

          newPos[i] = TargetPos[randNumber]; // all motors the same (random) new position

        }
        // eepromSave(); // could call eeprom write function here
        sequence = 2; // next case
        prevMillis = millis();
      }
      break;

and this also works fine.

If you agree with these changes, the next step is to check to see why I have a pretty long delay after the motors have reached their new position ? Any idea ? The ideal scenario will be for the motors to stay in their new position until the PIR sensor is triggered again. Logically the PIR sensor HIGH/LOW must be tested after the motors have reached the new position and not while they are moving.

I agree with you and was my intention to write the position to EEPROM not during the stepping loop but only after the motors are at their destination.
Maybe even better is to check if the PIR sensor is not triggered within a certain time (no one is if front of the panel) then write the last position to EEPROM , cut current to the motors and maybe even put Arduino in the sleep mode.

thank you.