Arrays and 74HC595N

void switchLED(byte led; boolean state)
{
byte barray[MaxShiftRegisters]; //how many 74HC59's onboard (8 bits per byte to modify)
//from B00000000 B00000000
for (int n=0; n<=MaxShiftRegisters; n++)
{

}

}

//eg (2 of these registers control 16 leds)
//switchLED(5,TRUE); //switch LED 5 on
//switchLED(10,TRUE); //switch LED 10 on
//switchLED(5,FALSE); //switch LED 5 false
//switchLED(5,FALSE); //switch LED 5 off

so 1 should look like (B10000000,B00000000)
9 should spit out (B00000000,B10000000)
16 should be (B00000000,B00000001)

I'm not fussed about switching on say led 1, 4, 8.. i'm only ever going to be lighting 1 LED at a time in any given sequence.

Any thoughts? cheers....

Any thoughts?

Use bitWrite() with 16 - the bit to set.

int outVal = 0;
bitWrite(outVal, 1); // 0x0001
bitWrite(outVal, 16); // 0x8000

that simple? huh ... cheers i'll try it....

Version 1+ requires 3 parameters.

void loop() 
{
  SomePattern();
}
int SetValToBin(int val)
{
   int n;
   for (int i=1; i<17; i++)
      bitWrite(n,i,0);

 for (int i=1; i<17; i++)
  {
    if (i==val)       
     {    
      bitWrite(n,i,1);
      return(n);
     } 
  }   

}


void SomePattern()
{
  byte hb,lb;
  int n,n2;
  for (n=1; n<17; n++)
   {
     n2=SetValToBin(n);
     hb=highByte(n2);
     lb=lowByte(n2);
     digitalWrite(latchPin, LOW);
     shiftOut(dataPin, clockPin, MSBFIRST, lb);  
     delay(1000);
     shiftOut(dataPin, clockPin, MSBFIRST, hb);
     digitalWrite(latchPin, HIGH);
     delay(800);     
   }
  
}

I'll post a video... but essentially LED1,2,3,4,5,6,7,8 all light up 9 (does not light up) 10,11,12,13,14,15,16 all light up, then back to 1, 2,3.... until it hits 9 then no lightoutput (i checked the pins, it's not a hardware fault as B11111111 works)
Ok, small issue, for some reason, it works just fine, except the first 8 LED's come on fine, then there's a pause/gap/delay and then i expected the next row of LED's to come on, which eventually
they do except it skips the first LED....

ah never mind, i got my high and low bytes mixed up.... working now thanks.

int SetValToBin(int val)
{
   int n;
   val--; //offset
   for (int i=0; i<17; i++)
      bitWrite(n,i,0);

 for (int i=0; i<17; i++)
  {
    if (i==val)       
     {    
      bitWrite(n,i,1);
      return(n);
     } 
  }   

}


void SomePattern()
{
  byte hb,lb;
  int n,n2;
  for (n=1; n<17; n++)
   {
     n2=SetValToBin(n);
     lb=highByte(n2);
     hb=lowByte(n2);
     digitalWrite(latchPin, LOW);
     shiftOut(dataPin, clockPin, MSBFIRST, lb);  
     shiftOut(dataPin, clockPin, MSBFIRST, hb);
     digitalWrite(latchPin, HIGH);
     delay(800);     
   }
  
}