Go Down

Topic: shift register acting funny (Read 611 times) previous topic - next topic

420kscott

Hi I'm rather new at the arduino thing. so i have not quite figured out all of the fixes. Recently i have been fiddling with a shift register though & the first time I put the circuit together with the code my project worked beautifully, I dis-assemblyed it & tried again & now for some reason, it works but the shift register is working in inverse! That is to say that the 1's are 0's & the 0's are 1's.

/*
Name: BINARY COUNTER (LED ON = 1, LED OFF = 0)
Notes: shift register - 74hc595
*/

//Control pins for Shift Register.
int L_Pin=8;    //latch pin - connected to ST_CP.
int C_Pin=12;   //clock pin - connected to SH_CP.
int D_Pin=11;    //data pin  - connected to DS.

void setup(){
  //Set control pins to output.
  pinMode(L_Pin,OUTPUT);
  pinMode(C_Pin,OUTPUT);
  pinMode(D_Pin,OUTPUT);
}
void loop(){
  for(int binNo=0; binNo<256; binNo++){
    digitalWrite(L_Pin,LOW);                  //L_Pin=0 - LED's remain const upload.
    shiftOut(D_Pin, C_Pin, MSBFIRST, binNo);  //Shift out byte.
                                              //MSBFIRST - Most Significant Bit FIRST
    digitalWrite(L_Pin,HIGH);                 //L_Pin=1 - LED's change for upload.
    delay(100);                               //Pause for next val.
  }
}

Go Up