Visualizing Binary with a Shift Register | Task 5

Use your shift register to display a visualization of binary numbers using LEDs



            // Visualization of binary numbers using LEDs
            
            int latchPin = 11;
            int clockPin = 9;
            int dataPin = 12;
            
            int dt = 1000;
            
            byte LEDs = 0B00000000;
            
            void setup() {
              // put your setup code here, to run once:
            pinMode(latchPin, OUTPUT);
            pinMode(clockPin, OUTPUT);
            pinMode(dataPin, OUTPUT);
            
            Serial.begin(9600);
            }
            
            void loop() {
              // put your main code here, to run repeatedly:
            digitalWrite(latchPin, LOW);
            shiftOut(dataPin, clockPin, LSBFIRST, LEDs);
            digitalWrite(latchPin, HIGH);
            delay(dt);
            LEDs = LEDs + 1;
            
            Serial.print(LEDs, BIN);
            Serial.print(" = ");
            Serial.println(LEDs);
            delay(dt);
            }
        
        

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