Arduino drum machine code is in the comment section

Опубликовано: 22 Октябрь 2024
на канале: Unrelated Activities
380
22

The interface is composed of one tactile switch, two rotary encoders with switch, a 128x64 I2C OLED display, some LEDs and an I2C EEPROM.
The display presents a grid with eight rows and sixteen columns, rows are tracks, columns are steps. The grid represents a one measure
pattern. Rotary encoders are used to navigate through the grid coordinates. The encoder X switch selects six modes: Edit, Tempo, Play,
Load, Save and Work Mode. In Edit mode, both X and Y encoders are used to navigate the grid and create or edit a pattern or a song. In
Tempo mode the X encoder sets the sequencer BPM (Beats Per Minute). Entering Play mode starts playing the current pattern. Load mode
allows the Y encoder to select and load patterns or songs previously stored in the I2C EEPROM. In Save mode a pattern or song can be
saved to EEPROM. Pattern size is 16 bytes, maximum song size is 2048 bytes (128 measures). Work mode is for selecting pattern or song
creation and edition. The Y encoder switch is used to select Cursor, Write, Measure, Step and Scale modes. In Cursor mode the selected
rectangular slot on the grid is highlighted by thicker lines. When the cursor passes over an actived slot (On) the slot is erased (Off).
In Write mode a filled square is drawn inside the next selected slot on the grid, indicating it is On. In Measure mode the Y encoder is
used to select which measure will be edited, while the X encoder is used to set the song size in measures. Step mode is for setting the
last step of the measures (9 - 16), and Scale sets the beat size in steps, its subdivision, from three to eight. The left side of the
display shows BPM tempo and the current modes: Top left is BPM value. Below BPM is the current mode selected by the X switch: Edit,
Tempo, Play, Load, Save and Work mode) indicated by the letters E, T, P, L, S, and m. Y switch mode is displayed using letters C, W, M, S
and B, for Cursor, Write, Measure, last Step and Scale (Beat subdivision). The Scale selected is indicated above the grid by short lines
over the first step of each beat. There are four numbers in the bottom line of the display, showing current pattern number, song last
measure, current measure, and pattern/measure last step. The last step is also indicated by an upward triangle below the grid. Each track
fires a gate using eight Arduino pins and also sends MIDI notes through TX pin (channel 10, GM drum notes 35, 38, 42, 46, 45, 50, 64, 76)
. The eight gates are serving also as LED drivers, indicating each track activity. A ninth LED (dual) serves as the metronome beat
indicator, red when the beat is the first of a measure, green for the remaining beats. In short, each pattern can have a maximum of
sixteen and a minimum of nine steps, beats can have three to eight steps depending on the scale setting. Each song can have a maximum of
128 measures/patterns. A song is arranged in a bi-dimensional array, this time a 128x16 array containing the 128 measures with sixteen
steps, the eight tracks are represented as the bits in a byte (kind of a bitmap). The main clock uses TimerOne library and seems to work
well if the OLED display is not updated during Play mode.

A 24LC512 I2C EEPROM is used to save data, organized as follows:
512 patterns (16 * 512 = 8192 bytes)
patterns tempo, scale and last step data (512 * 3 = 1536)
22 songs (2048 * 22 = 45056)