74HC595 shift register led "scanner" errors

Hello, I am trying to make a program for an assignment that makes one led turn off scanning back and forth continuously with a set time between the led changes (like a Knight Rider scanner but with one turning off instead of on) and despite a lot of googling and forum searching I cannot seem to find what i’m looking for.

Here is my code:

int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
 
byte leds [30] = {
B11111110, 100,
B11111101, 100,
B11111011, 100,
B11110111, 100,
B11101111, 100,
B11011111, 100,
B10111111, 100,
B01111111, 100,
B10111111, 100,
B11011111, 100,
B11101111, 100,
B11110111, 100,
B11111011, 100,
B11111101, 100,
};



void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {
  updateShiftRegister();
  delay(300);
  for (int count = 0; count < 15; count++)
  {
    bitSet(leds, count);
    updateShiftRegister();
    delay(300);
  }
}

void updateShiftRegister(){
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, leds);
  digitalWrite(latchPin, HIGH);
}

Firstly, as most of this code is borrowed from code others have made, i do not actually understand why byte leds[30] requires the number 30 there when there is only 14 rows of binary to scan through.

Secondly, this code seems to be totally non-functional, giving me the error

exit status 1
Error compiling for board Arduino/Genuino Uno.

whenever i try to verify it.

And thirdly, is there a more “elegant” method of making one led turn off and scan back and forth than the bunch of binary in the “byte leds” section?

Thankyou in advance to anyone who can help me out with this :slight_smile:

Get rid of all the 100 entries in the leds array. They are not used anywhere. If you initialize an array you do not have to state the size.

byte leds [] = {  // array has 14 elements numbered 0 through 13
B11111110,
B11111101,
B11111011, 
B11110111, 
B11101111, 
B11011111, 
B10111111, 
B01111111,
B10111111, 
B11011111, 
B11101111,
B11110111,
B11111011,
B11111101,
};
bitSet(leds, count);

Is useless here. Remove this.

Have a look at the array reference to see how to iterate through an array.

There are other ways to do what you want, but this method is simple.

requires the number 30 there when there is only 14 rows of binary to scan through.

Every row contains two byte values.

Secondly, this code seems to be totally non-functional, giving me the error

Correct, the code doesn't make sense as it is. To me it looks like the second part of the code was used to generate the byte array of the first. But as it's your code you should know which part is meant for what, don't you?

And thirdly, is there a more "elegant" method of making one led turn off and scan back and forth than the bunch of binary in the "byte leds" section?

This question is answered in the answer to the second question already.

I have updated my code and now it is not giving me any errors, but nothing seems to be happening on my board. None of the LEDs are turning on or anything.

Here’s my new code

int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
int count =0;
int timer = 200;
 
byte leds [] = {
B11111110,
B11111101,
B11111011,
B11110111,
B11101111, 
B11011111, 
B10111111, 
B01111111, 
B10111111,
B11011111,
B11101111,
B11110111,
B11111011,
B11111101,
};



void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {
  updateShiftRegister();
  delay(timer);
  for (count = 0; count<13; count++)
  {
    updateShiftRegister();
    delay(timer);
  }
}

void updateShiftRegister(){
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, leds);
  digitalWrite(latchPin, HIGH);
}

Again, thank you to anyone who can help and thank you pylon and groundFungus for your help so far :slight_smile:

Since this is a school assignment I can’t, in good conscience, give you the answer, but here is a hint. Look at these lines from the array reference.

int i;
for (i = 0; i < 5; i = i + 1) 
{
  Serial.println(myPins[i]);
}

See how the myPins array is iterated through by the for loop? And you should only call updateShiftRegister() from within the for loop.

does “call updateShiftRegister() from within the for loop” mean to get rid of the updateShiftRegister before the “for” like this?

void loop() {
   for (count = 0; count < 13; count = count + 1)
  {
    updateShiftRegister();
    delay(timer);
  }
}

Could you give me a hint as to whether i’m close to getting what i need at all with this code? or have i totally missed the mark?

"iterated through" sorry what does this mean?

iterate

In the for loop from the reference myPins is the array that gets iterated. In your programs leds is an array.

Thank you again groundFungus for providing an actual answer and not a passive aggressive link to a dictionary website...