Reset All LEDS Before "Next" Is Executed

I am working on a project with 480 LEDs, or 60 sections of 8 LEDs.

It looks like the attached .png.

Basically, I can turn on the one light in each section. I cannot however switch the light off.

This is connected to a Next button in VB, but I think the code in Arduino needs to be modified to reset all lights off before the next button is pushed. Is there a way to wrap all of this into a reset function?

//Arduino Code
 
int dataPin = 4;
int latchPin = 5;
int clockPin = 6;
byte leds = 0;

int a;
int b;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
int j;
int k; //variables are named all the way through to hhh in the chronology

 
void setup()
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);
  updateShiftRegister();
  Serial.begin(9600);
  while (! Serial); // Wait untilSerial is ready - Leonardo
  Serial.println("Enter LED Number 0 to 7 or 'x' to clear");
}
 
///
int   SerialResult=0;
int value;
void loop()
{
  if( Serial.available() )
  {
    char ch = Serial.read();
    if(ch >= '0' && ch <= '9') // is this an ascii digit between 0 and 9?
    {
       value = (value * 10) + (ch - '0'); // yes, accumulate the value
    }
    else if (ch == 10)  // is the character the newline character
    {
       SerialResult = value;  // set correct light
       Serial.println(SerialResult);
      value = 0; // reset val to 0 ready for the next sequence of digits
    }
    if (ch == '0')
    {
      a=0;
      b=0;
      c=0;
      d=0;
      e=0;
      f=0;
      g=0;
      h=0;
      i=0;
      j=0;
      k=0; //extends to hhh in the chronology
   

      updateShiftRegister();
    }
  }
 
  updateShiftRegister();
}
 
///
 
void updateShiftRegister()
 
{

   //************************* a
  if(SerialResult == 1)
 {a = 0x80;}
  if(SerialResult == 2)
 {a = 0x40;}
  if(SerialResult == 3)
 {a = 0x20;}
  if(SerialResult == 4)
 {a = 0x10;}
  if(SerialResult == 5)
 {a = 0x8;}
  if(SerialResult == 6)
 {a = 0x4;}
  if(SerialResult == 7)
 {a = 0x2;}
  if(SerialResult == 8)
 {a = 0x1;}
 
  //************************* b
  if(SerialResult == 9)
 {b = 0x80;}
  if(SerialResult == 10)
 {b = 0x40;}
  if(SerialResult == 11)
 {b = 0x20;}
  if(SerialResult == 12)
 {b = 0x10;}
  if(SerialResult == 13)
 {b = 0x8;}
  if(SerialResult == 14)
 {b = 0x4;}
  if(SerialResult == 15)
 {b = 0x2;}
  if(SerialResult == 16)
 {b = 0x1;}
 
  //************************* c
  if(SerialResult == 17)
 {c = 0x80;}
  if(SerialResult == 18)
 {c = 0x40;}
  if(SerialResult == 19)
 {c = 0x20;}
  if(SerialResult == 20)
 {c = 0x10;}
  if(SerialResult == 21)
 {c = 0x8;}
  if(SerialResult == 22)
 {c = 0x4;}
  if(SerialResult == 23)
 {c = 0x2;}
  if(SerialResult == 24)
 {c = 0x1;}

  //************************* d
  if(SerialResult == 25)
 {d = 0x80;}
  if(SerialResult == 26)
 {d = 0x40;}
  if(SerialResult == 27)
 {d = 0x20;}
  if(SerialResult == 28)
 {d = 0x10;}
  if(SerialResult == 29)
 {d = 0x8;}
  if(SerialResult == 30)
 {d = 0x4;}
  if(SerialResult == 31)
 {d = 0x2;}
  if(SerialResult == 32)
 {d = 0x1;}
 
  //************************* e
  if(SerialResult == 33)
 {e = 0x80;}
  if(SerialResult == 34)
 {e = 0x40;}
  if(SerialResult == 35)
 {e = 0x20;}
  if(SerialResult == 36)
 {e = 0x10;}
  if(SerialResult == 37)
 {e = 0x8;}
  if(SerialResult == 38)
 {e = 0x4;}
  if(SerialResult == 39)
 {e = 0x2;}
  if(SerialResult == 40)
 {e = 0x1;}
 
  //************************* f
  if(SerialResult == 41)
 {f = 0x80;}
  if(SerialResult == 42)
 {f = 0x40;}
  if(SerialResult == 43)
 {f = 0x20;}
  if(SerialResult == 44)
 {f = 0x10;}
  if(SerialResult == 45)
 {f = 0x8;}
  if(SerialResult == 46)
 {f = 0x4;}
  if(SerialResult == 47)
 {f = 0x2;}
  if(SerialResult == 48)
 {f = 0x1;}

  //************************* g
  if(SerialResult == 49)
 {g = 0x80;}
  if(SerialResult == 50)
 {g = 0x40;}
  if(SerialResult == 51)
 {g = 0x20;}
  if(SerialResult == 52)
 {g = 0x10;}
  if(SerialResult == 53)
 {g = 0x8;}
  if(SerialResult == 54)
 {g = 0x4;}
  if(SerialResult == 55)
 {g = 0x2;}
  if(SerialResult == 56)
 {g = 0x1;}

  //************************* h
  if(SerialResult == 57)
 {h = 0x80;}
  if(SerialResult == 58)
 {h = 0x40;}
  if(SerialResult == 59)
 {h = 0x20;}
  if(SerialResult == 60)
 {h = 0x10;}
  if(SerialResult == 61)
 {h = 0x8;}
  if(SerialResult == 62)
 {h = 0x4;}
  if(SerialResult == 63)
 {h = 0x2;}
  if(SerialResult == 64)
 {h = 0x1;}
 
  //************************* i
  if(SerialResult == 65)
 {i = 0x80;}
  if(SerialResult == 66)
 {i = 0x40;}
  if(SerialResult == 67)
 {i = 0x20;}
  if(SerialResult == 68)
 {i = 0x10;}
  if(SerialResult == 69)
 {i = 0x8;}
  if(SerialResult == 70)
 {i = 0x4;}
  if(SerialResult == 71)
 {i = 0x2;}
  if(SerialResult == 72)
 {i = 0x1;}

  //************************* j
  if(SerialResult == 73)
 {j = 0x80;}
  if(SerialResult == 74)
 {j = 0x40;}
  if(SerialResult == 75)
 {j = 0x20;}
  if(SerialResult == 76)
 {j = 0x10;}
  if(SerialResult == 77)
 {j = 0x8;}
  if(SerialResult == 78)
 {j = 0x4;}
  if(SerialResult == 79)
 {j = 0x2;}
  if(SerialResult == 80)
 {j = 0x1;}
 
  //************************* k
  if(SerialResult == 81)
 {k = 0x80;}
  if(SerialResult == 82)
 {k = 0x40;}
  if(SerialResult == 83)
 {k = 0x20;}
  if(SerialResult == 84)
 {k = 0x10;}
  if(SerialResult == 85)
 {k = 0x8;}
  if(SerialResult == 86)
 {k = 0x4;}
  if(SerialResult == 87)
 {k = 0x2;}
  if(SerialResult == 88)
 {k = 0x1;}
 
 // these if statements extend to hhh in the chronology
   
  {
  digitalWrite(latchPin, LOW);
// shiftOut extends to hhh in the chronology
   shiftOut(dataPin, clockPin, LSBFIRST, k);
   shiftOut(dataPin, clockPin, LSBFIRST, j);
   shiftOut(dataPin, clockPin, LSBFIRST, i);
   shiftOut(dataPin, clockPin, LSBFIRST, h);
   shiftOut(dataPin, clockPin, LSBFIRST, g);
   shiftOut(dataPin, clockPin, LSBFIRST, f);
   shiftOut(dataPin, clockPin, LSBFIRST, e);
   shiftOut(dataPin, clockPin, LSBFIRST, d);
   shiftOut(dataPin, clockPin, LSBFIRST, c);
   shiftOut(dataPin, clockPin, LSBFIRST, b);
   shiftOut(dataPin, clockPin, LSBFIRST, a);
   digitalWrite(latchPin, HIGH);
  }
}

As you see from the code below, I'm very new at this, but it works. From this code, i can turn on light # 1 in Section 1, light # 2 in Section 3, light # 5 in section 60, etc. through a .csv file (pushed by VB). I just can't turn that light off if the cell in the .csv = 0 (for no lights in the section). Rather, the previous light remains on.

LED Matrix.png

ScottA1:
I am working on a project with 480 LEDs, or 60 sections of 8 LEDs.

Your code can be massively reduced. Try (untested):

rowNumber =  1 + (SerialResult/8);  //row number 1 to 12
columnNumber = (SerialResult %8);  //mod 8 gives column number 0 - 7
switch(rowNumber){ //row number = 1 to 12
   case 1:  //first row
      a = (0x80 >>(7 - columnNumber)); //shift 80hex right (= /2) 0 to 7 times
      break;
   case 2:  //second row
      b = (0x80 >>(7 - columnNumber)); //shift 80hex right (= /2) 0 to 7 times
      break;
   case 3:  //third row
      c = (0x80 >>(7 - columnNumber)); //shift 80hex right (= /2) 0 to 7 times
      break;
   case 4: ......
   case 12:  // row 12
      k = (0x80 >>(7 - columnNumber)); //shift 80hex right (= /2) 0 to 7 times
      break;

   default:
      //something's gone wrong. Report error.
      break;
}

Henry_Best:
Your code can be massively reduced. Try (untested):

Thank you! It doesn't seem to work but it definitely gives me the idea.

I'm actually trying to see now if there is a way to say,

before executing all, first turn all off

I am interested in this idea. I am working on a halloween costume with the lilypad and an undetermined amount of LEDS. I am a total newb to arduino and sketching.

Scott, i am interested in hearing more about your project and what you are trying to do?

The problem is basically that you are saying "If I get this signal, turn this LED on", and that is being remembered because your variables are global.

You basically need to say "If I didn't receive anything for this block, set the variable for this block to 0".

You have signals that say "Turn LED X on". You really just need one more that says "Turn all LEDs off" - which is kind of like the "Turn LED X on" but for an LED that is "special" in that it turns the LEDs off (set it to 0x00) instead of turning one on.

ScottA1:
I'm actually trying to see now if there is a way to say,
before executing all, first turn all off

int AllOff;
setup(){
digitalWrite(latchPin, LOW);
for(AllOff = 1; AllOff <13; AllOff ++){ //do it 12 times
   shiftOut(dataPin, clockPin, LSBFIRST, 0);  //shift out zero
   }
digitalWrite(latchPin, HIGH);
}