Library for super EASY Teensy MIDI programming

Library for super EASY Teensy MIDI programming

Do you want to build your dream controller but don’t have the know-how or just can’t be bothered going through that complex process of programming? Not a problem at all, I have developed a library for Teensy that wraps up and hides the ugly process of reading pins and deciding whether to send MIDI signals or not, into couple of easy to use Classes. Just create an instance for each component of your controller, like Button, Potentiometer, LED etc and just with couple lines of code never bother again about the logic behind it.

Here is a simple example for a fully functioning one button and fader controller:

boolean debug=false; // print to serial instead of midi
boolean secondary=true; // enable secondary midi messages
int midiChannel=1; // midi channel number

// declare all your components here
Button but(17,midiChannel,1,secondary,debug); // button 1 on pin 17
Potentiometer pot(45,midiChannel,3,secondary,debug); // knob on pin 45 (A7)

void setup(){
}

void loop(){
// add here all the input component reads
pot.read(); // read knob and send midi messages
but.read(); // read buttons and send midi messages
}

Download: GitHub - ghztomash/MIDIElements: Wrapper library for easy MIDI programming on Teensy
Doc: MIDI Elements Teensy Library – Tomash GHz

The issue I have is the whole multiplexer thing; if I made my own controller, it’d have WAY more controls than the Teensy board can support :-\

You could definitely use each class with a multiplexer. Declare an array of Pots for example, all on the same pin. and then while reading through all the elements in a loop update the mux in selector.
Probably I will add a multiplexer class at some point :slight_smile:

Thanks for the sketches but I cant understand how to use them or put them together into a whole. could you do a brief explanation of how they fit together?

im trying to get 2 pot outputs and 2 button outputs from a gameport joystick.

Hey, if you open up the examples included with the library there is one empty template you could fill in and a complete working example with comments. Head over to MIDI Elements Teensy Library – Tomash GHz for the complete list of functions, classes and their description.

if you want to read 2 pots and 2 buttons from your teensy, then create two objects of each class, for example
Potentiometer pot1(the pin number the pot is connected on your teensy, midi channel you want it to send the message on, the control change number you want it to use); same for pot2, and the buttons but with different pin number and cc number,

then inside void loop call the read function for every instance, pot1.read(); pot2.read(); button1.read(); button2.read(); and that’s it!

also note that you have to set the USB Type to MIDI in the Arduino IDE or else the library will not compile.