74HC595 Shift Register and ShiftOut() - Pins Will Only Fire ... [SOLVED]


i'm attempting use 74h595 shift register control 24 total led's.  would them perform variety of tricks including chase, sparkle (fire random led, pause random burst, fire another,) pulse music etc.

as proof of concept, started single 74h595, wired per arduino shiftout tutorial exception of clockpin being 3, datapin 2, , latchpin 4.  fired them basic loop increments byte array b00000001 b10000000, , fires pins 1-8 in sequence expected.

tried same thing reversing loop (7 0) and, mysteriously, , continues firing pins 1-8.


things i've tried:
  • troubleshooting loop , pulled both counter , array value using serial.print().  it goes 7-0 , 128-1 expected.
  • checking circuit, rewiring it.
  • changing delay speed.  again nothing
  • writing 0 3 pins every time shiftout.  no noticeable effect.
  • clearing pins sending 0 shiftout().  no effect if performed every time.
  • tried changing values in array... making b00000001 b10101010 example.  there no effect.  while serial.print showed expected value, lights continued chase 1-8.
  • ran instructables "knight rider" code tweaked pin #'s.  it runs perfectly.
  • putting shiftout in own function (as anticipated, looked more orderly, made no difference.)


early on, suspected clock may run , incapable of firing in reverse order.  that doesn't make sense, however, instructables.com code fired expected; went up, down.  at point i'm little baffled , assuming either there's fundamentally wrong code or i'm trying perform not possible 74hc595.

code below.  any appreciated.
code: [select]

byte datapin = 2;              // serial data pin shift register
byte latchpin = 3;             // latch pin shift register
byte clockpin = 4;             // clock pin shift register

//my array of patterns
byte patterns[8] = { b00000001, b00000010, b00000100, b00001000, b00010000, b00100000, b01000000, b10000000 };


void setup()
{
    pinmode(datapin, output);    // configure digital pins
    
    pinmode(latchpin, output);
    
    pinmode(clockpin, output);  

    serial.begin(9600);
}


void loop()
{

  //thisworks();
  thisdoesnot();


}

// works fine
void thisworks()
{

  do {
  for (int i=0;i<8;i++)
  {
 
    digitalwrite(latchpin,low);
     shiftout(datapin,clockpin,msbfirst,patterns[i]);  
     digitalwrite(latchpin, high);
    delay(100);
  }
  } while (true);
}

// same above, despite fact should go in reverse.
void thisdoesnot()
{

  do {
  for (int i=7;i>=0;i--)
  {
     serial.print(i);
     serial.print("=");
     serial.println(patterns[i]);
     digitalwrite(latchpin,low);
     shiftout(datapin,clockpin,msbfirst,patterns[i]);  
     digitalwrite(latchpin, high);
    delay(100);
  }
  } while (true);
}

figured out @ last - simple switch of clockpin , latchpin did trick.  makes loads of sense , explains pretty handily.  little things!


Arduino Forum > Using Arduino > Programming Questions > 74HC595 Shift Register and ShiftOut() - Pins Will Only Fire ... [SOLVED]


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code