Displaying Binary Numbers with LEDs | Task 4

In this task, you will see a basic sketch using the shiftOut function to control LEDs with a 74HC595 shift register.



// Laser Bar

int latchPin = 11;
int clockPin = 9;
int dataPin = 12;

int dt = 500;

byte LEDs_1 = 0B01010101;
byte LEDs_2 = 0B10101010;

void setup() {
  // put your setup code here, to run once:
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, LEDs_1);
digitalWrite(latchPin, HIGH);
delay(dt);

digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, LEDs_2);
digitalWrite(latchPin, HIGH);
delay(dt);
}


        

Watch the video below to understand how the code works in action: