title: How to light up specific LED's and also shift every other led with a 74HC595 shift register?
body: <p>I am currently in the process of building a drum machine with a micro controller. I am trying to figure out the logic of the sequencer. I have 16 LED's which will indicate at which 16th note the drum machine currently is playing. </p>
  
  <p>So for instance, let's say the beats per minute (BPM) is 120, then the led should shift twice every second.</p>
  
  <p>So for the shifting part I have written code such that if the step number is 0, we shift in a 1. If the step number is > 0, we shift in a 0. The method is called every (60/BPM) seconds.</p>
  
  <p>PD5 is the serial input,
  PD4 is the latch pin, PD3 is the clock pin.</p>
  
  <pre><code>void update_led(void) {
      if (step_number == 0){
         PORTD |= (1 &lt;&lt; PD5); //Send a 1
         PORTD |= (1 &lt;&lt; PD4); //Read the input to 1st led
         PORTD &amp;= ~(1 &lt;&lt; PD5);
         PORTD &amp;= ~(1 &lt;&lt; PD4);
         PORTD |= (1 &lt;&lt; PD3); //Shift to next led
         _delay_ms(40);  //Apparently I need a delay here to light up LED
        PORTD &amp;= ~(1 &lt;&lt; PD3);
      }else{
        PORTD |= (1 &lt;&lt; PD4);
        PORTD &amp;= ~(1 &lt;&lt; PD4);
        PORTD |= (1 &lt;&lt; PD3);
        _delay_ms(40);
        PORTD &amp;= ~(1 &lt;&lt; PD3);
     }
   }           
  </code></pre>
  
  <p>But I also want the LEDs to static be lit for each step a user has programmed a sound. So for instance if the user presses button 1 and 5 and 9 and 13 with the instrument kick drum, the LED 1,5,9,13 should be static lit up but the leds should also shift like the above code. Does anyone have any tips on how to efficiently implement this? Is there a smart way to make a specific LED always light up when shifting the other LED's?</p>