Understanding blinking program



I’m trying to understand the blinking LED program:

First, I don’t understand how the frequency of the LED is obtained.

Then here we are doing something really weird:

assign LED = blink_pattern[blink_counter[25:21]];
we are assigning 5 bits to blink pattern and that goes to LED… I don’t understand it.

I would appreciate any guidance.

Thank you!


Here’s the original line from the source code:

assign LED = blink_pattern[blink_counter[25:21]];

If I separate that line out a bit it might help your understanding of it:

// pattern_index is a 5-bit counter that always counts up. It counts
// up slowly so that the LED pattern is recognizable by humans.
assign pattern_index = blink_counter[25:21];

// blink_pattern defines the pattern to blink the LED.  It contains
// '1's and '0's to define when the LED should be on and off. We
// use pattern_index to index into the blink_pattern and determine
// if the LED should currently be on or off.
assign LED = blink_pattern[pattern_index];

Try changing the values in blink_pattern and see what happens.