The sequence runs using a timer interrupt, with the value being calculated using BPM, the formula converts the BPM to Hz and then to the timer value that creates 24 pulses per quater note, so it can also send MIDI clock
This is then divided up into 16th notes and a beat pulse (for the LED)
This allows the sequence to run, while the chip can carry on processing input.
There are 3 main chips that do the work:
ATMEGA 644 - Main sequencer and controller
ATMEGA 328 - LED controller, takes a clock and reset line, and serial data to set the pattern
ATTINY 85 - Scans the push buttons and sends serial to the main chip on change
I could have used the main MPU to do everything, but that would have meant a lot of code, this was a big project to start with, it was far easier to use dedicated chips.
A clock pulse is sent every 16th note to the LED controller, which increments from left to right, the controller for the LEDs ATMEGA328 receives serial data to set the 'sequence' when that part is being edited. Exclusive OR commands make the LED go out when the step hits it.
When the sequence is stopped a reset pulse is sent to start it all over again, the sequencer doens't have a pause option.
All the note data for the sequence is stored in a multi dimensional array, along with the MIDI port, Channel and velocity command.
The sequence scans 8 individual parts for one step.