Hi my project is based on http://www.arduino.cc/en/Tutorial/ShiftOut and Overview | Arduino Lesson 4. Eight LEDs and a Shift Register | Adafruit Learning System.
What I have is the board set up like in the Shift Out tutorial just with 7 led's per shift register instead of 8 that is shown in the tutorial.
As for code what I have for now is:
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
byte leds = 0;
int firstSet = 1;
int secondSet = 2;
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
leds = 0;
//For first set of (red) leds / first shift register
if(firstSet==1)
{
disleds0();
}
else if(firstSet==2)
{
disleds1();
}
else if(firstSet==3)
{
disleds2();
}
//For second set of (green) leds / second shift register
if(secondSet==1)
{
disleds0SS();
}
else if(secondSet==2)
{
disleds1SS();
}
else if(secondSet==3)
{
disleds2SS();
}
}
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}
void disleds0()
{
bitSet(leds, 0); //if firstSet == 1 light up the first led
updateShiftRegister();
}
void disleds1()
{
bitSet(leds, 1); //if firstSet == 2 light up the second led
updateShiftRegister();
}
void disleds2()
{
bitSet(leds, 2); //if firstSet == 3 light up the third led
updateShiftRegister();
}
void disleds0SS()
{
bitSet(leds, 0); //if secondSet == 1 light up the first led on the second shift register
updateShiftRegister();
}
void disleds1SS()
{
bitSet(leds, 1); //if secondSet == 2 light up the second led on the second shift register
updateShiftRegister();
}
void disleds2SS()
{
bitSet(leds, 2); //if secondSet == 3 light up the third led on the second shift register
updateShiftRegister();
}
(I left out some of the repeating code to make the code easier to read.)
So the problem is that when I run the code with firstSet = 1 and secondSet = 2 the first two led's for both sets of led's are lighting up when in this case I would only want the first led to light on the first set of led's / shift register and for only the second led on the second set of led's / second shift register.
In more straight forward way how do I send specific data to each shift register.
(as far as I know i have to send a second shift out, I think, I just don't know how to do it. )
Thanks in advance.