Arduino Slider Phased Rhythms

There is an interesting video going around social media of someone playing a simple drum beat at 120bpm, 119bpm and 121bpm and you can hear the rhythms going in and out of phase, so I thought it perhaps time to update my Arduino Mux Slider Phased Relays to actually play a rhythm.

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

These are the key Arduino tutorials for the main concepts used in this project:

If you are new to Arduino, see the Getting Started pages.

Parts list

The Circuit

ArduinoPhasedPots_bb

The simplest form of this circuit is shown above.  Basically we need one potentiometer for each track we want to include in the playback.  The potentiometer will control the timing of the playback of that track.  It is also possible to include an optional “global” tempo control.

But having already played with phasing of relay ticks and pitched sequences with my Arduino Multi-Slider MIDI Controller I thought this might be another good application for that too.  The following details how I set that to be used, but it can be ignored if you are using the simple version above – just jump straight to the code!

I decided to just use one bank of 8 slider potentiometers, so rather than use a multiplexer, in this instance I thought I’d use an Arduino Nano directly.  There are a few adjustments required to my board and code to allow this:

  • Only one set of 8 slider pots is being used.
  • The two jumpers underneath that can be used to pre-enable certain pins when using a multiplexer should be unconnected.
  • The board will get power and ground from D6 and D7.
  • A MIDI interface can be connected to the MIDI header breakout pins on the board.

IMG_5997

The Arduino Nano has all 8 analog inputs connected to slider pots and RX, TX, power and GND broken out to a MIDI header.  The other pin headers are not being used.

IMG_5996

The Code

There are elements of this code from both of the following previous projects, so for more detailed explanations, refer back to those:

The basic idea is to configure a drum track, which has a specified number of steps (I’m using 8) and has the possibility of playing up to two notes (corresponding to drums) on each step (I’m using 2). This is my drum track:

#define NUM_NOTES 2
#define NUM_STEPS 8
int steps[NUM_STEPS][NUM_NOTES] = {
/* Step 0 */ { 35, 42 }, 
/* Step 1 */ { 0, 0 }, 
/* Step 2 */ { 0, 42 }, 
/* Step 3 */ { 0, 0 }, 
/* Step 4 */ { 38, 42 }, 
/* Step 5 */ { 0, 0 }, 
/* Step 6 */ { 0, 42 }, 
/* Step 7 */ { 0, 0 }, 
};

This is using the following drum notes (from the General MIDI drum track specification):

  • 35 – Acoustic bass drum
  • 38 – Acoustic snare drum
  • 42 – Closed hi-hat

The number of potentiometer and number of parallel tracks to be playing should match.  In my example with my sliders, I’m using four.  If you are just using two pots, you should set this to two of course.  Each track can have its own MIDI channel, but I’ve set them all to channel 10, which is the general MIDI drum channel.

#define NUM_TRACKS 4
int midichan[NUM_TRACKS]={10, 10, 10, 10};

The way the code works, is largely the same as with the previous two projects.  Each track has a counter, whose maximum value is set from the potentiometers, and when that counter reaches its maximum the next step for that track is played and the counter is reset.

As before, each step has a minimum “tick” governed by a period timer configured using the TimerOne library.

In this example, the code is set up as follows:

  • The minimum tick is 5mS, so there are 200 “ticks” a second (see the MIN_TEMPO value).
  • The minimum count for each track’s timer is 20 ticks (see the MINTICK value).

When all potentiometers are at “zero” this means each track will play one step every 20 x 5mS ticks or every 100mS.  Changing the potentiometers will add to the MINTICK and adjust the timings of when each track has to play a note.  I’ve right-shifted the potentiometer value to make it in the range 0 to 255, so the largest “tick” for a step is 275 x 5mS or around 1.3 seconds.

There is also the option of a global tempo change potentiometer.  This changes the period of the timer.  I’ve multiplied it up, so the actual period of the tick can be anything between 5mS and almost 10mS.  This means that the minimum step (when the pots are a zero) can vary with the global tempo between 100mS and 200mS – or from 10 ticks a second to around 5 ticks a second.

This means the corresponding step times can vary from that 100mS/200mS value up to around 1.3 seconds at the low end and over 2.5 seconds at the high end.

The global tempo control can be disabled by commenting out the TEMPO_POT definition.

There are many other options in the code: it is possible to use potentiometers via a multiplexer as described here; there is an option for “fake power/ground” when using a Nano “slider shield” (as I am); the number of steps, tracks, notes per step, and potentiometers are all configurable…

And of course, the rhythm I’ve hard-coded into the code is pretty simple.  There are lots of possibilities!

Find it on GitHub here.

Closing Thoughts

I’ve configured my board for four tracks and a global tempo pot, using five of the 8 slider pots on the board, but some good effects can be found with just two tracks and two pots.

There are so many possibilities for phasing experiments, I’ve really only just scratched the surface with my projects so far.  I really should find the time to explore it a little more.

Kevin

Leave a comment