multiple shift registers separately connected driving LEDs


hi,

i trying build 24-led array. need grid of 4 x 6 leds @ specific distance 1 another. want able determine each individual led whether on or off, , want able determine frequency (the length of on time , of off time) of blinking of each set of 6 leds (that is, ones destined on).

i have connected 4 shift registers (74hc595), each own 3 pins of arduino micro. each of 4 shift registers have connected 6 leds.

i connected 595's according arduino shift out tutorial.

https://www.arduino.cc/en/tutorial/shiftout

but, instead of connecting second, third , forth shift register previous one, connected each shift register separate set of 3 pins:

pin 5.5 v arduino volt rail bread board
pin ground arduino ground rail bread board
cathodes leds common ground
anodes leds pins shift registers

shift registers:

q1 q6 (pin 1 - 6) anodes 6 leds
q7 (pin 7) floating
gnd (pin 8) common ground bread board
q7" (pin 9) floating
mr10 (pin 10) volt rail bread board
sh-cp (pin 11) latch pin arduino pin 11, 8, 5, 2 respectively
st-cp (pin 12) clock pin arduino pin 10, 7, 4, 13 respectively
oe (pin 13) common ground bread board
ds (pin 14) data pin arduino pin 12, 9, 6, 3 respectively
q0 (pin 15) floating
vcc (pin 16) volt rail bread board

i made sketch based on code amanda ghassaei, allows me determine leds on , off. part works. if connect arduino , upload sketch leds should turn on, turn on, , others don't.

http://www.instructables.com/id/intermediate-arduino-inputs-and-outputs/

but, give me control on frequency of blinking, added code, amanda, using millis function. doesn't have effect. suspect once data sent shift register pins, can't undo setting latch pin low. but, bit @ loss here. so, suggestion appreciated.

many in advance having @ circuit , code.

code: [select]
//sketch based on code amanda ghassaei intermediate arduino: inputs , outputs instructables

//set 595_1 state
int clockpin1 = 10;
int latchpin1 = 11;
int datapin1 = 12;

int intervalon1 = 100; //length of time led on (pulse width)
int intervaloff1 = 900; //length of time led off (1 hz)

int ledstate = low; // current state of led
unsigned long timeoflastledevent = 0; //the last time led updated

//set 595_2 state
int clockpin2 = 7;
int latchpin2 = 8;
int datapin2 = 9;

int intervalon2 = 100; //length of time led on (pulse width)
int intervaloff2 = 400; //length of time led off (2 hz)

//set 595_3 state
int clockpin3 = 4;
int latchpin3 = 5;
int datapin3 = 6;

int intervalon3 = 100; //length of time led on (pulse width)
int intervaloff3 = 9900; //length of time led off (0.1 hz)

//set 595_4 state
int clockpin4 = 13;
int latchpin4 = 2;
int datapin4 = 3;

int intervalon4 = 100; //length of time led on (pulse width)
int intervaloff4 = 4900; //length of time led off (0.2 hz)

byte numbertodisplay1 = 682;
byte numbertodisplay2 = 27;
byte numbertodisplay3 = 7;
byte numbertodisplay4 = 44;

void setup() {
//all connections 595 outputs
pinmode(latchpin1, output);
pinmode(clockpin1, output);
pinmode(datapin1, output);

digitalwrite(latchpin1, ledstate);

pinmode(latchpin2, output);
pinmode(clockpin2, output);
pinmode(datapin2, output);

digitalwrite(latchpin2, ledstate);

pinmode(latchpin3, output);
pinmode(clockpin3, output);
pinmode(datapin3, output);

digitalwrite(latchpin3, ledstate);

pinmode(latchpin4, output);
pinmode(clockpin4, output);
pinmode(datapin4, output);

digitalwrite(latchpin4, ledstate);

}

void loop() {

unsigned long currentmillis = millis();

if (ledstate == low){//if led off
  if (currentmillis - timeoflastledevent > intervaloff1){//and enough time has passed
    digitalwrite(latchpin1, high);//turn latchpin1 on
    if (currentmillis - timeoflastledevent > intervaloff2){
    digitalwrite(latchpin2, high);
    if (currentmillis - timeoflastledevent > intervaloff3){
    digitalwrite(latchpin3, high);
    if (currentmillis - timeoflastledevent > intervaloff4){
    digitalwrite(latchpin4, high);

    ledstate = high;//store current state
    timeoflastledevent = currentmillis;//update time of new event
   
    shiftout(datapin1, clockpin1, lsbfirst, numbertodisplay1);
    shiftout(datapin2, clockpin2, lsbfirst, numbertodisplay2);
    shiftout(datapin3, clockpin3, lsbfirst, numbertodisplay3);
    shiftout(datapin4, clockpin4, lsbfirst, numbertodisplay4);
    }
    }
    }     
  }
} else {//if led on
  if (currentmillis - timeoflastledevent > intervalon1){
    digitalwrite(latchpin1, low); //turn latchpin1 off
    if (currentmillis - timeoflastledevent > intervalon2){
    digitalwrite(latchpin2, low);
    if (currentmillis - timeoflastledevent > intervalon3){
    digitalwrite(latchpin3, low);
    if (currentmillis - timeoflastledevent > intervalon4){
    digitalwrite(latchpin4, low);
    ledstate = low;
    timeoflastledevent = currentmillis;
  }
  }
  }
 }
 }
 }

quote
you can't undo setting latch pin low. but, bit @ loss here. so, suggestion appreciated.
you can turn on leds off applying signal output enable of shift registers. in effect turns shift register outputs off.

if don't want on leds blink can send 2 alternating patterns shift registers in conventional way.


Arduino Forum > Using Arduino > LEDs and Multiplexing > multiple shift registers separately connected driving LEDs


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor