Peter Sikkens
Peter Sikkens

Reputation: 1

Shift register receiving 33 bits - all outputs high instead of in sequence (Arduino Uno)

I seem to have an issue where, when I send 33 bits out through 5 shift registers to LEDs (only using one output on the final register) it loops through array entries 1-15 just fine, but then flashes the remaining LEDs all at once before restarting the loop. Using an Elegoo Uno R3, (5x)sn74hc595n shift registers.

The code below was to test the LEDs in order, the bits in the array will be replaced with other combinations of LEDS for a display to show.

Could anyone spot where my error is? Thank you.

const int latchpin = 10;
const int clockpin = 11;
const int datapin = 12;

int ledarray[] = {
  0b000000000000000000000000000000001,
  0b000000000000000000000000000000010,
  0b000000000000000000000000000000100,
  0b000000000000000000000000000001000,
  0b000000000000000000000000000010000,
  0b000000000000000000000000000100000,
  0b000000000000000000000000001000000,
  0b000000000000000000000000010000000,
  0b000000000000000000000000100000000,
  0b000000000000000000000001000000000,
  0b000000000000000000000010000000000,
  0b000000000000000000000100000000000,
  0b000000000000000000001000000000000,
  0b000000000000000000010000000000000,
  0b000000000000000000100000000000000,
  0b000000000000000001000000000000000,
  0b000000000000000010000000000000000,
  0b000000000000000100000000000000000,
  0b000000000000001000000000000000000,
  0b000000000000010000000000000000000,
  0b000000000000100000000000000000000,
  0b000000000001000000000000000000000,
  0b000000000010000000000000000000000,
  0b000000000100000000000000000000000,
  0b000000001000000000000000000000000,
  0b000000010000000000000000000000000,
  0b000000100000000000000000000000000,
  0b000001000000000000000000000000000,
  0b000010000000000000000000000000000,
  0b000100000000000000000000000000000,
  0b001000000000000000000000000000000,
  0b010000000000000000000000000000000,
  0b100000000000000000000000000000000,
};
int arraysize = sizeof(ledarray)/sizeof(ledarray[0]);
int arrayplace = 0;

void setup() {
 
pinMode(latchpin, OUTPUT);
pinMode(clockpin, OUTPUT);
pinMode(datapin, OUTPUT);
}

void loop() {

   for (int arrayplace = 0; arrayplace < arraysize; arrayplace ++){
     digitalWrite(latchpin, LOW);
     shiftOut(datapin, clockpin, MSBFIRST, ledarray[arrayplace] >> 32 ); // send bit(s)(40-)33
     shiftOut(datapin, clockpin, MSBFIRST, ledarray[arrayplace] >> 24 ); // send bits 32-25
     shiftOut(datapin, clockpin, MSBFIRST, ledarray[arrayplace] >> 16 ); // send bits 24-17
     shiftOut(datapin, clockpin, MSBFIRST, ledarray[arrayplace] >> 8  );  // send bits 16-9
     shiftOut(datapin, clockpin, MSBFIRST, ledarray[arrayplace]       );  // send bits 8-1
     digitalWrite (latchpin, HIGH);
     delay (100);


}
}

Upvotes: 0

Views: 14

Answers (0)

Related Questions