I ordered some shift registers to play around with but I can't make heads or tails of any other the tutorials. Does anyone know of a tutorial that actually makes sense? Like say I want to turn on pin 1 and 4 how can I do that? Everything I see is set up to just turn something on and off in order in, like the nightrider thing and that seems useless..

The documentation for shiftOut says:

shiftOut() Description

Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. Each bit is written in turn to a data pin, after which a clock pin is pulsed to indicate that the bit is available.

The tutorials define how to write a bit, and toggle the clock pin.

As for the data to output, you might want to have a look at bitSet, bitRead(), bitWrite(), and bitClear(). These functions allow you to manipulate individual bits in a byte, which is what you seem to want to do.

Once you have the byte to output, shift it out just like the tutorials show.

Would anybody be willing to write some example code for switching pin 1 on and off?

Pin 1 is one of the pair of pins used for serial I/O. It is better not to use that pin, unless you absolutely have to. It will interfere with uploading sketches.

const int pinNum = 1;
digitalWrite(pinNum, HIGH); // Turn pin on
digitalWrite(pinNum, LOW);  // Turn pin off

Thanks for your quick replies. Sorry I should have been more clear in my question. Pin 1 of the shift register. Thanks again!

I presume that you have seen this:

I presume, also that you have your shift register connected as shown here:

Further, I presume that you mean you want to set only output pin 1 high.

byte outVal = 0; // Define output data
bitSet(outVal, 1); // Set bit 1
shiftOut(dataPin, clockPin, MSBFIRST, outVal);

(You may need to change MSBFIRST to LSBFIRST, if the right pin does not light up).

Alright.... What about pin 2 of the shift register? These things are so complicated to me for some reason...

bitSet(outVal, 2); // Set bit 2

Please don’t ask how to set bit 3 :slight_smile: