Step 11All About The Code
I did my absolute best to make the code user-friendly. The code includes many comments to help you understand what is going on. You are not required to write any code, more-so, just fill in the blanks. Easy. Only if you want to add some LED features will you need to append some basic code. There is an LED example provided within the code to get you started.
I was never trained as a coder, but I do consider this code to be pretty damn good! Thanks to my brother Neil for help with some of the more difficult sections.
The code is broken up into five sections:
- Edit - The section where you are required to make the appropriate edits related to your controller using a fill-in-the-blanks method.
- Variables and functions - Holds the variables and functions used by the code.
- Setup - This is where we define out pin configuration, informing the Teensy which pin in an input and which is an output.
- Loop - The brains of our whole operation. This function loops over and over while the Teensy is running.
- Communication functions - These functions handle our messages.
If you are not using Traktor software, you will likely have to edit the rotary encoder MIDI messages. Check your software's documentation to understand the expected message format. When you figure it out please message me so I can add it to this Instructable.
Although it is not imperative to understand all the code, I just want to explain one snippet of code which will help you understand how the control messages work. The code below sends analog messages for a potentiometer. There are three modes (debug, I2C, and MIDI) which you turn on/off in the edits. If debug is enabled, messages will be sent through USB to the serial monitor to help with debugging. 'serialDebugOut' is a very basic function I wrote which sends these serial messages and it can be viewed at the bottom of the code. If I2C is enabled, messages will be sent through I2C to the master module which will then forward the messages through USB. If MIDI is enabled, then this controller will send MIDI messages directly through USB to the computer. 'usbMIDI.' is a specific message used by Teensy++ for MIDI messages. Read more about Teensy MIDI here. Keep in mind you can edit the code to send many kinds of messages: Teensy USB Serial, Teensy USB Keyboard, Teensy USB Mouse, Teensy USB Joystick, Teensy USB MIDI, and Arduino Serial.
if(enableDebug==1){ //SERIAL debug is on
serialDebugOut("Analog",i,tempAnalogInMap);
}
else if(enableI2C==1){ //I2C
serialI2COut('a',i,tempAnalogInMap,channelNumber);
}
else{ //MIDI
usbMIDI.sendControlChange(i,tempAnalogInMap,channelNumber);
}
Read the code/comments over and over, it make take a few iterations to wrap your head around. You can learn a lot from the code. Constantly reference the Arduino library for sections you don't understand.
The rotary encoder code is a nasty beast. If you are feeling ambitious you can read more about it here.
**Likely there will be some improvements made to the code over time so continue to check back for the latest version.**
All code can be found here at GitHub. For this section use the code titled 'Controller Code'. Click 'ZIP' in the top-left to download.
| « Previous Step | Download PDFView All Steps | Next Step » |






















































I also tried to separate the *edit* sections a little more from the "please do not edit" sections :-) You have one codeblock to edit - the LED section - the rest is pin connections, and modes of behaviour.
Still have question about nature of SHIFT key and what it does in this context.
Very nice Instructable. super useful. thanks
changes-xtl