Fader Value MIDI Encoding with Teensy 3.2

Hello there,

I am helping with a school project to build a lighting desk. We have the basic parts, including a small desk with a low number of faders, and this is where my task comes in. The software, Magicq by Chamsys is able to use MIDI to change fader values in the software, so I have to code a teensy 3.2 that can take the analogue input from a linear pot, encode it into a midi note, which then gets sent to Chamsys over USB where Chamsys decodes it, and uses it to change the value on one of the software faders. The problems that I am currently experiencing are that a): The fader value in analogue form is fairly jumpy, and will not stay at the same value for more than about half a second, it (the value) moves around with around a +-10 tolerance. b): I have no real idea how to encode an analogue value into MIDI, and then send it over USB.

Any help would be much appreciated!



To solve your first problem, you could average multiple analog readings.
A MIDI Control Change value is 7 bits wide, while the result from analogRead is 10 bits wide. So just shift the reading 3 bits to the right using the bitshift operator (>>).

You might be interested in my MIDI Controller library. This makes it very easy to create a MIDI controller, with a lot of features, but with clean, simple code. For example:

#include <MIDI_controller.h> // include the library

const static byte Channel_Volume = 0x7; // controller number 7 is defined as Channel Volume in the MIDI implementation.
const static size_t analogAverage = 8; // Use the average of 8 samples to get smooth transitions and prevent noise

Analog fader1(A0, Channel_Volume, 1); // Create a new instance of the class 'Analog, called 'fader1', on pin A0, that sends MIDI messages with controller 7 (channel volume) on channel 1.
Analog fader2(A1, Channel_Volume, 2);
Analog fader3(A2, Channel_Volume, 3);
Analog fader4(A3, Channel_Volume, 4);

void setup(){
  USBMidiController.blink(LED_BUILTIN);  // flash the built-in LED (pin 13 on most boards) on every message
  USBMidiController.setDelay(15);  // wait 15 ms after each message not to flood the connection
  USBMidiController.begin();  // Initialise the USB MIDI connection
  delay(1000); // Wait a second...

  fader1.average(analogAverage); // Use the average of 8 samples to get smooth transitions and prevent noise

void loop(){
  fader1.refresh(); // refresh the fader (check whether the input has changed since last time, if so, send it over MIDI)


Thanks, I'll give it a look now!

Thanks Pieter, this solved my problem!

Great project, I would be really interested too.
Do you have any more details? Scheme, sketch?

Everything you need can be found on the GitHub page of the MIDI Controller library. Installation instructions in the README, example code in the examples folder (or from the IDE menu), documentation on the Wiki, hardware help and schematics on the Wiki, and more information about MIDI over USB and board recommendations on the Wiki.

Please note that the sketch in this thread is no longer compatible with the new versions of the library.