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.