Well firstly, remove the capacitor (it's wrong) but I can't remember off hand exactly what that example does.
Here's some code written by bhagman (from Rogue Robotics) which turns on/off an LED (0-15) in either red, blue or purple (both). I'm using 4 daisy chained shift registers - the first two controlling red LEDs and the second two controlling blue LEDs. The values for the previous LEDs are stored so the other LEDs remain as they were when you turn another one on/off.
void setLED(uint8_t lednum, uint8_t colour)
{
red_leds = (red_leds & ~(1 << lednum));
blue_leds = (blue_leds & ~(1 << lednum));
if (colour == LED_RED || colour == LED_PURPLE)
{
red_leds |= (1 << lednum);
}
if (colour == LED_BLUE || colour == LED_PURPLE)
{
blue_leds |= (1 << lednum);
}
shiftOut(dataPin, clockPin, MSBFIRST, (uint8_t) (blue_leds >> 8));
shiftOut(dataPin, clockPin, MSBFIRST, (uint8_t) blue_leds);
shiftOut(dataPin, clockPin, MSBFIRST, (uint8_t) (red_leds >> 8));
shiftOut(dataPin, clockPin, MSBFIRST, (uint8_t) red_leds);
digitalWrite(latchPin, HIGH);
delayMicroseconds(10);
digitalWrite(latchPin, LOW);
}
void clearLEDs()
{
red_leds = 0;
blue_leds = 0;
for (int i = 0; i < 4; i++)
{
shiftOut(dataPin, clockPin, MSBFIRST, 0);
}
digitalWrite(latchPin, HIGH);
delayMicroseconds(10);
digitalWrite(latchPin, LOW);
}
You then need this sort of stuff at the top of your sketch:
/////////////////////////SHIFT REGISTER LED STUFF
const int latchPin = 8;//Pin connected to latch pin (ST_CP) of 74HC595
const int clockPin = 12;//Pin connected to clock pin (SH_CP) of 74HC595
const int dataPin = 11;//Pin connected to Data in (DS) of 74HC595
uint16_t red_leds;
uint16_t blue_leds;
#define LED_OFF 0
#define LED_RED 1
#define LED_BLUE 2
#define LED_PURPLE 3
/////////////////////////