Midi Message Tester Mini-Project
I wanted to test out different kinds of midi messages in FL Studio, and needed a way to toggle between messages and their values. I could have found a way to do this with software, but really wanted to play with this 2 x 16 character LCD screen.
Knowing how to build this is not necessary for the step pedal midi controller, so I’m not going to cover this in great detail. This post is mainly for my records, but you can use these images and the following code to create this yourself if you like.
Note that I used a number pad for an easy to use array of buttons. The buttons in the above diagram are connected to ground and one of the input pins, 0 though 6, on the Teensy 3.1 (not shown for simplicity).
Adruino Code
My Arduino sketch include two extra tabs, to help me organize the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#include <Bounce2.h> #include <LiquidCrystal.h> LiquidCrystal lcd(7,8,9,10,11,12); const int channel = 1; int msgNumber = 0; int var1 = 60; int var2 = 99; Bounce dbsendMsg = Bounce(); Bounce dblastMsg = Bounce(); Bounce dbnextMsg = Bounce(); Bounce dbfirstInc = Bounce(); Bounce dbfirstDec = Bounce(); Bounce dbsecondInc = Bounce(); Bounce dbsecondDec = Bounce(); void setup() { lcd.begin(16, 2); SetupButtons(); // Write first midi message name lcd.setCursor(0, 0); lcd.print(GetMessage(msgNumber)); } void loop() { UpdateButtons(); // Print variable numbers below midi message lcd.setCursor(0, 1); lcd.print(var1); lcd.print(", "); lcd.print(var2); lcd.print(" "); //Toggle Messages if (dblastMsg.fell()) { msgNumber -= 1; lcd.setCursor(0, 0); lcd.print(GetMessage(msgNumber)); lcd.print(" "); } else if (dbnextMsg.fell()) { msgNumber += 1; lcd.setCursor(0, 0); lcd.print(GetMessage(msgNumber)); lcd.print(" "); } // Increment/Decrement Message Variables if (dbfirstInc.fell()) var1 += 1; else if (dbfirstDec.fell()) var1 -= 1; if (dbsecondInc.fell()) var2 += 1; else if (dbsecondDec.fell()) var2 -= 1; // Send selected message if (dbsendMsg.fell()) SendMidiMsg(msgNumber, var1, var2); //Discard incoming midi messages. while (usbMIDI.read()) { } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
const int sendMsgPin = 2; const int lastMsgPin = 1; //1 const int nextMsgPin = 0; //4 const int firstIncPin = 4; //2 const int firstDecPin = 3; //5 const int secondIncPin = 6; //2 const int secondDecPin = 5; //5 void SetupButtons() { // Setup all input pins pinMode(sendMsgPin, INPUT_PULLUP); pinMode(lastMsgPin, INPUT_PULLUP); pinMode(nextMsgPin, INPUT_PULLUP); pinMode(firstIncPin, INPUT_PULLUP); pinMode(firstDecPin, INPUT_PULLUP); pinMode(secondIncPin, INPUT_PULLUP); pinMode(secondDecPin, INPUT_PULLUP); // Setup all debouncer objects dbsendMsg.attach(sendMsgPin); dbsendMsg.interval(5); dblastMsg.attach(lastMsgPin); dblastMsg.interval(5); dbnextMsg.attach(nextMsgPin); dbnextMsg.interval(5); dbfirstInc.attach(firstIncPin); dbfirstInc.interval(5); dbfirstDec.attach(firstDecPin); dbfirstDec.interval(5); dbsecondInc.attach(secondIncPin); dbsecondInc.interval(5); dbsecondDec.attach(secondDecPin); dbsecondDec.interval(5); } void UpdateButtons(){ // Update all debounce objects dbsendMsg.update(); dblastMsg.update(); dbnextMsg.update(); dbfirstInc.update(); dbfirstDec.update(); dbsecondInc.update(); dbsecondDec.update(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
// Message to appear at the top of the LCD screen char* GetMessage(int msgNumber) { switch (msgNumber) { case 0: return "NoteOn: Note,Vel"; case 1: return "NoteOff: Note"; case 2: return "PolyPress:Nte,Pr"; case 3: return "CtrlChg:Cont,val"; case 4: return "PrgmChng:Program"; case 5: return "AftrTch:Pressure"; case 6: return "PitchBend: Value"; // case 7: return "SysEx"; default: return "Invalid:"; } } //Send the message with the selected variables void SendMidiMsg(int msgNumber, int var1, int var2){ switch (msgNumber) { case 0: usbMIDI.sendNoteOn(var1, var2, channel); break; case 1: usbMIDI.sendNoteOn(var1, 0, channel); break; case 2: usbMIDI.sendPolyPressure(var1, var2, channel); break; case 3: usbMIDI.sendControlChange(var1, var2, channel); break; case 4: usbMIDI.sendProgramChange(var1, channel); break; case 5: usbMIDI.sendAfterTouch(var1, channel); break; case 6: usbMIDI.sendPitchBend(var1, channel); break; // case 7: // usbMIDI.sendSysEx(length, array); // break; } } |