Mechatronics LAB
Published © Apache-2.0

Arduino Workshop-Shift Register 8-Bit Binary Counter

In this project, we are going to use additional ICs in the form S

BeginnerFull instructions provided1 hour6,697
Arduino Workshop-Shift Register 8-Bit Binary Counter

Things used in this project

Story

Read more

Schematics

Arduino Workshop-Shift Register 8-Bit Binary Counter

Code

Code snippet #1

Arduino
int latchPin = 8;   // Pin connected to Pin 12 of 74HC595 (Latch)
int clockPin = 12;  // Pin connected to Pin 11 of 74HC595 (Clock)
int dataPin = 11;   // Pin connected to Pin 14 of 74HC595 (Data)

void setup() {
  // Set pins to output
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}

void loop() {
  // Count from 0 to 255
  for (int i = 0; i < 256; i++) {
    shiftDataOut(i);
    // Set latchPin low then high to send data out
    digitalWrite(latchPin, LOW);
    digitalWrite(latchPin, HIGH);
    delay(1000);
  }
}

void shiftDataOut(byte dataOut) {
  // Shift out 8 bits LSB first, clocking each with a rising edge of the clock line
  for (int i = 0; i <= 7; i++) {
    digitalWrite(clockPin, LOW); // Set clockPin to LOW prior to sending bit
    // If the value of dataOut and a bitmask are true, set pinState to HIGH
    boolean pinState = dataOut & (1 << i) ? HIGH : LOW;
    // Set dataPin to HIGH or LOW depending on pinState
    digitalWrite(dataPin, pinState); // Send bit out before rising edge of clock
    digitalWrite(clockPin, HIGH);
  }
  digitalWrite(clockPin, LOW); // Stop shifting out data
}

Credits

Mechatronics LAB

Mechatronics LAB

67 projects • 44 followers
I am Sarful , I am a Mechatronics Engineer & also a teacher I am Interested in the evolution of technology in the automation industry .

Comments