lot of eguivalent structures e.g Shift595...how to?

This is part of my code....

#include <Shift595.h>

#define dataPin0 A0
#define dataPin1 A3
#define dataPin2 3
#define dataPin3 6

#define latchPin0 A1
#define latchPin1 A4
#define latchPin2 4
#define latchPin3 7

#define clockPin0 A2
#define clockPin1 A5
#define clockPin2 5
#define clockPin3 8
#define Sh_R_line 4
int numOfRegisters[]= {4,2,4,2} ;

Shift595 Sh_R0(dataPin0, latchPin0, clockPin0, numOfRegisters[0]);
Shift595 Sh_R1(dataPin1, latchPin1, clockPin1, numOfRegisters[1]);
Shift595 Sh_R2(dataPin0, latchPin2, clockPin2, numOfRegisters[2]);
Shift595 Sh_R3(dataPin1, latchPin3, clockPin3, numOfRegisters[3]);

void Sh_R0_stop_pin(int i){Sh_R0.setRegisterPin(i-1, LOW);Sh_R0.setRegisterPin(i+7, LOW);}
void Sh_R0_forward(int i){Sh_R0.setRegisterPin(i-1, HIGH);Sh_R0.setRegisterPin(i+7, LOW);}
void Sh_R0_reverse(int i){Sh_R0.setRegisterPin(i-1, LOW);Sh_R0.setRegisterPin(i+7, HIGH);}

void Sh_R1_stop_pin(int i){Sh_R1.setRegisterPin(i-1, LOW);Sh_R1.setRegisterPin(i+7, LOW);}
void Sh_R1_forward(int i){Sh_R1.setRegisterPin(i-1, HIGH);Sh_R1.setRegisterPin(i+7, LOW);}
void Sh_R1_reverse(int i){Sh_R1.setRegisterPin(i-1, LOW);Sh_R1.setRegisterPin(i+7, HIGH);}

void Sh_R2_stop_pin(int i){Sh_R2.setRegisterPin(i-1, LOW);Sh_R2.setRegisterPin(i+7, LOW);}
void Sh_R2_forward(int i){Sh_R2.setRegisterPin(i-1, HIGH);Sh_R2.setRegisterPin(i+7, LOW);}
void Sh_R2_reverse(int i){Sh_R2.setRegisterPin(i-1, LOW);Sh_R2.setRegisterPin(i+7, HIGH);}

void Sh_R3_stop_pin(int i){Sh_R0.setRegisterPin(i-1, LOW);Sh_R3.setRegisterPin(i+7, LOW);}
void Sh_R3_forward(int i){Sh_R0.setRegisterPin(i-1, HIGH);Sh_R3.setRegisterPin(i+7, LOW);}
void Sh_R3_reverse(int i){Sh_R0.setRegisterPin(i-1, LOW);Sh_R3.setRegisterPin(i+7, HIGH);}

It would be better if you could use something like that

Shift595 Sh_R*(dataPin0, latchPin0, clockPin0, numOfRegisters[0]);*
in and cycle...
Any idea?
dummie.ino (1.88 KB)

It would be better if you could use something like that

You can create an array of Shift595 objects:

Shift595 Sh_R[] =
{
  Shift595(dataPin0, latchPin0, clockPin0, numOfRegisters[0]),
  Shift595(dataPin1, latchPin1, clockPin1, numOfRegisters[1]),
  Shift595(dataPin0, latchPin2, clockPin2, numOfRegisters[2]),
  Shift595(dataPin1, latchPin3, clockPin3, numOfRegisters[3])
};

PaulS:
You can create an array of Shift595 objects:

Shift595 Sh_R[] =

{
  Shift595(dataPin0, latchPin0, clockPin0, numOfRegisters[0]),
  Shift595(dataPin1, latchPin1, clockPin1, numOfRegisters[1]),
  Shift595(dataPin0, latchPin2, clockPin2, numOfRegisters[2]),
  Shift595(dataPin1, latchPin3, clockPin3, numOfRegisters[3])
};

if it works ... that's what i need...I'll fold the structure and try.TNX

m_veidemanis:
if it works ... that's what i need...I'll fold the structure and try.TNX

It works...Excelent!Tnx again!

#include <Shift595.h>

byte  dataPin[]={A0,A3,3,6};   
byte  latchPin[]={A1,A4,4,7};    
byte  clockPin[]={A2,A5,5,8}; 
int   numOfRegisters[]= {4,4,4,4} ;     
     
Shift595 Sh_R[] =
{
  Shift595(dataPin[0], latchPin[0], clockPin[0], numOfRegisters[0]),
  Shift595(dataPin[1], latchPin[1], clockPin[1], numOfRegisters[1]),
  Shift595(dataPin[2], latchPin[2], clockPin[2], numOfRegisters[2]),
  Shift595(dataPin[3], latchPin[3], clockPin[3], numOfRegisters[3])
};

void stop_pin(int i,int adr){Sh_R[adr].setRegisterPin(i-1, LOW);Sh_R[adr].setRegisterPin(i+7, LOW);}
void forward(int i,int adr){Sh_R[adr].setRegisterPin(i-1, HIGH);Sh_R[adr].setRegisterPin(i+7, LOW);}
void reverse(int i,int adr){Sh_R[adr].setRegisterPin(i-1, LOW);Sh_R[adr].setRegisterPin(i+7, HIGH);}


void setup()
{
 
  for (int address=0;address<4;address++)
  {
    for(int pin=1;pin<9;pin++)
      {forward(pin,address);delay(50);stop_pin(pin,address);}
    for(int pin=8;pin>0;pin--)
      {reverse(pin,address);delay(50);stop_pin(pin,address);}
  }
}

void loop()
{

}

all fragment..