Hand-controlled CV sequencer firmware for mudras.ino.
Mudras is a gestural sequencer for modular and CV-based instruments. It uses a VL53L0X time-of-flight sensor to track hand position, converts that motion into either quantized pitch CV or smooth linear control voltage, and records/playbacks sequences in sync with an external gate or clock.
The name comes from mudras — hand gestures used in classical Indian dance and yoga. Like their namesake, each hand position produces a distinct musical expression.
- Hand-position control with a VL53L0X distance sensor
- External clock/gate input for step advancement
- Record and playback modes selected with a button
- Variable loop lengths from 2 to 64 steps
- 7 quantized musical scales plus 1 linear CV mode
- 12-bit DAC CV output on
PA4
Mudras Uses a STM32G431, but it will work and this code is compatible with any STM32 Chip that has a built in DAC
| Pin | Function |
|---|---|
D4 |
Record/play button input (INPUT_PULLUP, active low) |
D5 |
External gate/trigger input, falling-edge interrupt |
PA0 |
Loop length knob |
PA1 |
Scale selection knob |
PA4 |
12-bit DAC CV output |
SDA/SCL |
I2C connection to VL53L0X sensor |
- An external trigger on
D5advances the sequencer. - The interrupt service routine only sets a flag.
- Step advance, record, and playback logic are handled in the main loop.
- Hold the
D4button to record. - Release the
D4button to play back the stored sequence. - Entering record mode from playback resets recording to step 0.
The distance sensor is read continuously:
- In scale modes, hand distance is mapped to a note index.
- In linear mode, hand distance is mapped directly to the full 12-bit DAC range.
The scale knob selects one of 8 modes:
| Mode | Behavior |
|---|---|
| 0 | Major |
| 1 | Dorian |
| 2 | Minor Pentatonic |
| 3 | Harmonic Minor |
| 4 | Diminished |
| 5 | Whole Tone |
| 6 | Chromatic |
| 7 | Linear CV (no quantization) |
The loop length knob selects one of these sequence lengths:
- 2 steps
- 3 steps
- 4 steps
- 8 steps
- 16 steps
- 32 steps
- 64 steps
- Hand distance is mapped to a scale index.
- The scale table converts that index to a note.
- The note is converted to volts using 1V/octave.
- Voltage is converted to a 12-bit DAC value.
- The DAC outputs CV on
PA4.
- Hand distance is mapped directly to
0-4095. - The raw DAC value is recorded or played back.
- The DAC outputs smooth unquantized CV on
PA4.
This sketch depends on:
WireAdafruit_VL53L0XResponsiveAnalogRead
- DAC output uses 12-bit resolution.
- I2C is configured for 400 kHz.
- The sequencer stores up to 64 steps in memory.
- The external gate input is expected to be level-shifted/protected before reaching
D5. - The step counter starts at -1 so that the first incoming gate increments it to step 0 before any playback or recording happens.
If you are new to modular synthesis, these terms appear throughout the code and documentation:
- CV (Control Voltage): An analog voltage signal used to control a parameter — such as pitch or filter cutoff — in modular synthesizers. Mudras outputs CV on pin
PA4. - 1V/Octave: The standard relationship between voltage and pitch in modular synths. Each 1-volt increase raises the pitch by one octave (12 semitones). This is how
midi_note_to_volts()works in the firmware. - Gate / Trigger: A short voltage pulse used to clock or advance sequencers. Mudras receives a gate on
D5to step forward. - Sequencer: A device that stores and replays a series of notes or CV values in order, synchronized to a clock.
- Quantization: Snapping a continuous value (like hand position) to the nearest note in a musical scale. Scale modes 0–6 do this; Linear mode (7) does not.
- DAC (Digital-to-Analog Converter): Hardware that converts a number (0–4095 in 12-bit) into an analog voltage. The STM32G431's built-in DAC on
PA4is used here. - Time-of-Flight sensor: The VL53L0X measures distance by timing how long a laser pulse takes to bounce off your hand and return.
- Power the module and connect the VL53L0X sensor.
- Feed an external clock or gate into
D5. - Set loop length with the knob on
PA0. - Choose a scale or linear mode with the knob on
PA1. - Hold
D4and move your hand over the sensor to record steps. - Release
D4to play the sequence back.
- Main firmware:
mudras.ino