Addressing Individual Outputs on Shift Register

Evening Folks

I'm a tad green on the programming side and i'm just starting to break into using Shift Registers to control a larger set of outputs

perhaps someone can help me find the missing gap between what i know and what i need to know

My current use & understanding when im programming an output is as follows

i want to turn an LED on so:

pinMode(13, OUTPUT);

and then in the main loop:

digitalWrite(13, HIGH);

so now for example i have my shift register with my 8 (or 16 or 32 depending on how many are chained) how do go about making the following happen

turn on led 1,2,3,4,5

make LED 6 Flicker
Make LED 7 Pulse

the gap in my knowledge is that i don't know what i need to learn to get to the next stage all i've seen on shift register tutorials is nice flashing patterns programmatically made i.e. turn on LED then move it to the next LED and strobe around the run

I'm interested in using the shift register pins as sold on or off outputs with addresses i can control (using for an art instillation where say 20/30 LEDs will be on solid and a few of them will do various things depending on where i put them)

hopefully someone can make sense of my request and point me in the right direction !

thanks !!

turn on led 1,2,3,4,5

make LED 6 Flicker
 Make LED 7 Pulse

You have to put out all 8 bits to the shift register every time you want to change any of the values. This happens very quickly and is (usually) not noticeable.

The simple way is to keep an array of 8 bytes (or booleans) and to have a single output function "put the array out to the shift register". To make leds flicker or pulse, you have your usual code using millis(), but instead of digitalWrite to a pin, you put the on/off value in the correct element of your array and call your output function.

Having said that:

Cave you considered using Adafruit Neopixels? They come in strips, circles, and as individual pixels in various sizes and form factors. You can chain any number of them (connect the 'out' of one to the 'in' of the next) and drive them all with a single output pin. There's a base library that makes it all much easier, and people have written higher-layer libraries that encode various effects and thingies that art people might be interested in doing like fading, cycling, displaying a picture on a grid and so on.

If you are more interested in art than in electronics and just want some easy blinkenlights that work well, I do recommend them.

PaulMurrayCbr:
Having said that:

Cave you considered using Adafruit Neopixels? They come in strips, circles, and as individual pixels in various sizes and form factors. You can chain any number of them (connect the 'out' of one to the 'in' of the next) and drive them all with a single output pin. There's a base library that makes it all much easier, and people have written higher-layer libraries that encode various effects and thingies that art people might be interested in doing like fading, cycling, displaying a picture on a grid and so on.

If you are more interested in art than in electronics and just want some easy blinkenlights that work well, I do recommend them.

NeoPixels Products Category on Adafruit Industries

Thanks for that I'm most definitely interested in doing it for myself i'm also bound by dimensions using a Specific LED etc

I'm quite confident on the electronics side just never ventured further than bashing a few scripts together to get a desired result, i'm decidedly more on the hardware side than software haha

in response to your first segment however:

PaulMurrayCbr:

turn on led 1,2,3,4,5

make LED 6 Flicker
Make LED 7 Pulse




You have to put out all 8 bits to the shift register every time you want to change any of the values. This happens very quickly and is (usually) not noticeable.

The simple way is to keep an array of 8 bytes (or booleans) and to have a single output function "put the array out to the shift register". To make leds flicker or pulse, you have your usual code using millis(), but instead of digitalWrite to a pin, you put the on/off value in the correct element of your array and call your output function.

Are you aware of any tutorials or snippets i could get my teeth into regarding Arrays, and addressing contents

arrays and shift registers are programming wise very new to me

from what you've posted i'd need to write something along the lines of the following within the main loop (just flowcharted):

Clear register;
Write array to shift;

define the array;

define first bit of array (solid on);
define second bit of array(flashing code);
define Third bit of array (Pulsing code);

Thanks once again for your response!! I just need to learn how to convert the process language from my head into code haha

I welcome any further comment or guidance!

You can use bitWrite to set individual bits before sending them to the shift register.

You can use shiftOut to move the data to the shift register.

// variable that holds the value to send to the shift register
byte outputValue;

// set the least significant bit to high
bitWrite(outputValue, 0, HIGH);

// set the latch pin low
digitalWrite(latchPin, LOW);

// shift
shiftOut(dataPin, clockPin, MSBFIRST, outputValue);

// set the latch pin high; rising edge will make the new value take affect.
digitalWrite(latchPin, HIGH);

You need to play with the thrid parameter of the shiftOut function. Wheater you need to set a bit high or low depends on how the LED are wired.

You can clear outputValue (if needed) before setting the bits or keep it as is and only modify bits that you want to modify.

Code for 74HC595 shiftRegister; might work for others or not. You can do a little research, there are plenty examples for the 74HC595. Code not tested nor compiled.

Remember series resistors and honour the limits; I think the max current in total is 70mA so you can not have 8 leds at 10mA on permanently.