Go Down

Topic: Need Help plz on a counter with shift registers (Read 279 times) previous topic - next topic

TicTacWhat

Hi, im really new to the arduino as well as the shift registers 74HC595. I believe that i have issues with setting up the shift registers as I am using three of them but im not sure if they are properly set up or just burnt out. My first 2 shift registers were set up correctly but when i placed my third one up by connecting the overload of shift register #2 to the data pin of shift register #3 the 2nd 7 segment display stopped displaying numbers properly. I connected all of the latch and clock pins from shift register #3 to shift register #2 and im not sure if that is the issue as maybe ur suppose to connect them to shift register #1? I'd really appreciate the help as it is no longer counting and the numbers on my 7 segment displays are just displaying 8. Here is my coding if it is incorrect as well. Thank you very much.


int dataPin1 = 5;
int latchPin1 = 6;
int clockPin1 = 7;
int sensor = A0;
int count1 = 0;
int count2 = 0;
int count3 = 0;

void setup()
{
  //Configure each IO Pin
    pinMode(dataPin1, OUTPUT);
    pinMode(latchPin1, OUTPUT);
    pinMode(clockPin1, OUTPUT);
    Serial.begin(9600);
}

void loop()
{
  int sensorvalue = analogRead(sensor);
  if (sensorvalue > 600)
  {
    count1++;
  }
  if (count1 == 10)
  {
    count1 = 0;
    count2++;
  }
  if (count2 == 10)
  {
    count2 = 0;
    count3++;
  }
  if (count3 == 10)
  {
    count3 = 0;
  }
  if(sensorvalue > 600) {
    Serial.print ("count1 = ");
    Serial.println(count1);
    Serial.print ("count2 = ");
    Serial.println(count2);
    Serial.print ("count3 = ");
    Serial.println(count3);
    delay (200);
  }

  digitalWrite(latchPin1, LOW);   
   if (count3 == 0)
  {   
    shiftOut(dataPin1, clockPin1, MSBFIRST, 0x3F);
  }       
  if (count3 == 1)
  {
    shiftOut(dataPin1, clockPin1, MSBFIRST, 0x06);
  }
  if (count3 == 2)
  {
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x5b);
  }
  if (count3 == 3)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x4F);   
  }
  if (count3 == 4)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x66); 
  }
  if (count3 == 5)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x6D);
  }
  if (count3 == 6)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x7D); 
  }
  if (count3 == 7)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x07);
  }
  if (count3 == 8)
  {
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x7F);
  }
  if (count3 == 9)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x6F);
  }
  if (count2 == 0)
  {   
    shiftOut(dataPin1, clockPin1, MSBFIRST, 0x3F);
  }       
  if (count2 == 1)
  {
    shiftOut(dataPin1, clockPin1, MSBFIRST, 0x06);
  }
  if (count2 == 2)
  {
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x5b);
  }
  if (count2 == 3)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x4F);   
  }
  if (count2 == 4)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x66); 
  }
  if (count2 == 5)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x6D);
  }
  if (count2 == 6)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x7D); 
  }
  if (count2 == 7)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x07);
  }
  if (count2 == 8)
  {
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x7F);
  }
  if (count2 == 9)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x6F);
  }
   
   
  if (count1 == 0)
  {
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x3F); 
  }
  if (count1 == 1)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x06);     
  }
  if (count1 == 2)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x5B);   
  }
  if (count1 == 3)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x4F); 
  }
  if (count1 == 4)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x66); 
  }
  if (count1 == 5)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x6D);
  }
  if (count1 == 6)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x7D);   
  }
  if (count1 == 7)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x07);
  }
  if (count1 == 8)
  {
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x7F);     
  }
  if (count1 == 9)
  {   
          shiftOut(dataPin1, clockPin1, MSBFIRST, 0x6F);
  }
  digitalWrite(latchPin1, HIGH);
}

Go Up