I think you have to show your code.
yeah it was basically the code you gave me, modified for shift register usage
it works when my loop is like this:
void loop(){
// Turn on "Number" randonm LEDs
for (int i=0; i<Number; i++) {
do {
thisPin = random(8);
alreadySet = pattern & (1<<thisPin);
pattern |= (1<<thisPin);
setRegisterPin(thisPin, HIGH);
writeRegisters();
}
while (alreadySet); // If the LED was already on, try a different one
}
pattern = 0;
delay(timer);
clearRegisters();
}
but as soon as I change the 8 in:
thisPin = random(8)
to a higher number, (starting to use the second shift register, which is a 74HC595 by the way) I get the problem (most of the time the desired amount of LEDs are burning but about 10% of the time a couple of them don't light up)
Here is the complete code if needed
int timer = (1000);
int SER_Pin = 8; //pin 14 on the 75HC595
int RCLK_Pin = 9; //pin 12 on the 75HC595
int SRCLK_Pin = 10; //pin 11 on the 75HC595
int Number = 4;
int thisPin;
int alreadySet;
#define shiftCount 2 //How many shift registers
#define pinCount shiftCount * 8 //How many pins
boolean registers[pinCount];
unsigned long pattern;
void setup(){
pinMode(SER_Pin, OUTPUT);
pinMode(RCLK_Pin, OUTPUT);
pinMode(SRCLK_Pin, OUTPUT);
Serial.begin(9600);
//reset all register pins
clearRegisters();
writeRegisters();
}
//set all register pins to LOW
void clearRegisters(){
for(int i = 0; i < pinCount; i++){
registers[i] = LOW;
}
}
//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){
digitalWrite(RCLK_Pin, LOW);
for(int i = pinCount - 1; i >= 0; i--){
digitalWrite(SRCLK_Pin, LOW);
int val = registers[i];
digitalWrite(SER_Pin, val);
digitalWrite(SRCLK_Pin, HIGH);
}
digitalWrite(RCLK_Pin, HIGH);
}
//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
registers[index] = value;
}
void loop(){
// Turn on "Number" randonm LEDs
for (int i=0; i<Number; i++) {
do {
thisPin = random(8);
alreadySet = pattern & (1<<thisPin);
pattern |= (1<<thisPin);
setRegisterPin(thisPin, HIGH);
writeRegisters();
}
while (alreadySet); // If the LED was already on, try a different one
}
pattern = 0;
delay(timer);
clearRegisters();
}