74HC595 Shift Register Help

I am rather new to the Arduino, and am trying to figure out the code for the 74HC595 shift register. I have read the ShiftOut references and tutorials on Arduino.cc, and think I understand the general idea as to how this works. Out of all of the examples they offer, I still don't exactly know how to best code what I am trying to do.

Basically, all I want to do is be able to turn on any one of the 8 LEDs I have hooked up to the 74HC595 at a time, and turn the others off (only one LED lit at a time). What is the best way to go about this?

Thanks,

-TC

Shift out 8 bits, and make sure the seven you want turned of is 0

Should I do the dataArray similar to the ShiftOut example in the Arduino Tutorial at http://www.arduino.cc/en/Tutorial/ShftOut13 ?

So, in that example, dataArray[8] = 0x18; //00011000 would mean LEDs 4 and 5 would be switched on, and the rest off when I Shift Out dataArray[8]?

Thanks for the help,

-TC

Yup!

And Arduino’s flavor of C++ seems to support binary constants, so if you just wanted the first and last LEDs you could even just write:

shiftOut(dataPin, clockPin, 0b10000001);

No need to create dataArray, unless it suits your needs. If you just want to turn on a single LED, you could write a function like:

void turnonled(int dataPin, int clockPin, int LEDno) // pass LED number from 0-7
{
  shiftOut(dataPin, clockPin, 1 << LEDno);
}

Mikal

Wow, that was easier than I thought it was going to be. Thanks so much for the help!

-TC