MIDI song display

Hello,

I am totally new to all of this and don't really know a lot yet. I am trying to make a small LCD display which will display a message (in this case the name of a song) depending on what MIDI message it receives. On the top row it will respond to MIDI CC commands. And the bottom row will respond to NOTE ON commands.

I am using an Arduino Uno and I bought a MIDIlickuino and LCD screen from here:

Here is an example of what I want it to do:
If I send a MIDI CC of 101, the LCD will show "song 1" on the top row.
If I send a MIDI CC of 102, the LCD will show "song 2" on the top row.
If I send a MIDI CC of 103, the LCD will show "song 3" on the rop row.
etc... There are 14 songs in total.

On the bottom row I want it to display the preset number within the song of which there will be 3 (A,B and C). For example:
If I send a MIDI NOTE ON of 0, the LCD will show "A"
If I send a MIDI NOTE ON of 1, then the LCD will show "B"
If I send a MIDI NOTE ON of 2, then the LCD will show "C"

I initially edited some code I found online which was for a MIDI monitor. And what I have now, I had help from the guys at the store where I bought the MIDIlickuino and LCD screens. However, it doesn't seem to be working. It just says "waiting" but doesn't react to my MIDI signals at all.

Here is the code I have so far:


#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2,3,4,5,6,7);

byte incomingByte;//stock the first receive byte
byte cc;//stock the second receive byte
byte value;// stock the 3rd receive byte
byte message;//Message type
byte channel;//MIDI channel
byte note;//note

void setup(){
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
//set midi baud rate
Serial.begin(31250);
//Home message
lcd.setCursor(0,0);
lcd.print(" NAME OF BAND ");
lcd.setCursor(0,1);
lcd.print("NAME OF BAND LIVE");
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Waiting...");

}

void loop() {

if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
message = (incomingByte>>4)- B1000;//convert the first byte to find the message type
channel = (incomingByte & B1111) +1;//convert the first byte to find the MIDI Channel
//print the MIDI channel
if(incomingByte<=240){// is it a message system?

if (message ==3){//is it a message Control Change?
cc = Serial.read();// read Control change value
switch (cc) {
case 101:
lcd.setCursor(0,0);
lcd.print("SONG 1");//THE NAME HAVE TO BE 16 CHARACTER
break;
case 102:
lcd.setCursor(0,0);
lcd.print(" SONG 2 ");
break;
case 103:
lcd.setCursor(0,0);
lcd.print(" SONG 3 ");
break;
case 104:
lcd.setCursor(0,0);
lcd.print(" SONG 4 ");
break;
case 105:
lcd.setCursor(0,0);
lcd.print(" SONG 5 ");
break;
case 106:
lcd.setCursor(0,0);
lcd.print(" SONG 6 ");
break;
case 107:
lcd.setCursor(0,0);
lcd.print(" SONG 7 ");
break;
case 108:
lcd.setCursor(0,0);
lcd.print(" SONG 8 ");
break;
case 109:
lcd.setCursor(0,0);
lcd.print(" SONG 9 ");
break;
case 110:
lcd.setCursor(0,0);
lcd.print(" SONG 10 ");
break;
case 111:
lcd.setCursor(0,0);
lcd.print(" SONG 11 ");
break;
case 112:
lcd.setCursor(0,0);
lcd.print(" SONG 12 ");
break;
case 113:
lcd.setCursor(0,0);
lcd.print(" SONG 13 ");
break;
case 114:
lcd.setCursor(0,0);
lcd.print(" SONG 14 ");
break;
}
}
if (message ==1){//is it a message noteON?
note = Serial.read();// read Control change value
switch (note) {
case 11:
lcd.setCursor(0,1);
lcd.print(" A ");
break;
case 12:
lcd.setCursor(0,1);
lcd.print(" B ");
break;
case 13:
lcd.setCursor(0,1);
lcd.print(" C ");
break;
}
}
}
}
}

Just use basic math.

switch (cc) {
case 101:
lcd.setCursor(0,0);
lcd.print("SONG 1");//THE NAME HAVE TO BE 16 CHARACTER
break;
case 102:
lcd.setCursor(0,0);
lcd.print(" SONG 2 ");
break;
case 103:
lcd.setCursor(0,0);
lcd.print(" SONG 3 ");
break;
case 104:
lcd.setCursor(0,0);
lcd.print(" SONG 4 ");
break;
case 105:
lcd.setCursor(0,0);
lcd.print(" SONG 5 ");
break;
case 106:
lcd.setCursor(0,0);
lcd.print(" SONG 6 ");
break;
case 107:
lcd.setCursor(0,0);
lcd.print(" SONG 7 ");
break;
case 108:
lcd.setCursor(0,0);
lcd.print(" SONG 8 ");
break;
case 109:
lcd.setCursor(0,0);
lcd.print(" SONG 9 ");
break;
case 110:
lcd.setCursor(0,0);
lcd.print(" SONG 10 ");
break;
case 111:
lcd.setCursor(0,0);
lcd.print(" SONG 11 ");
break;
case 112:
lcd.setCursor(0,0);
lcd.print(" SONG 12 ");
break;
case 113:
lcd.setCursor(0,0);
lcd.print(" SONG 13 ");
break;
case 114:
lcd.setCursor(0,0);
lcd.print(" SONG 14 ");
break;
}

All of this can be changed to:
LCD.print("Song ");
LCD.print(cc - 100); // be careful here, is cc a single byte, or individual chars('1', '0', '0') that need to be converted to a single number?

Same with this but you are just converting the number to the corresponding letter.

if (message ==1){//is it a message noteON?
note = Serial.read();// read Control change value
switch (note) {
case 11:
lcd.setCursor(0,1);
lcd.print(" A ");
break;
case 12:
lcd.setCursor(0,1);
lcd.print(" B ");
break;
case 13:
lcd.setCursor(0,1);
lcd.print(" C ");
break;
}
}

LCD.print(note + 54); // 'A' = 65(dec) -> 'A' - 11(note) = 54

I, too, reduced the switch. I don't have an LCD display handy, but you can see how it works with the serial monitor.

void setup() {
  Serial.begin(115200);
}

void loop() {
  char message[17];
  char input[17];
  int bytesRead;
  int cc;
  
  if (Serial.available() > 0) {
    bytesRead = Serial.readBytesUntil('\n', input, 16);
    input[bytesRead] = '\0';
    cc = atoi(input);
    if (cc > 100 && cc < 115) {
      cc %= 100;                  // cc now is 1 to 14
      itoa(cc, input, 10);
      //lcd.setCursor(0, 0);
      strcpy(message, "   SONG ");
      strcat(message, input);
      strcat(message, "   ");
      Serial.println(message);
      //lcd.print(message); 
    } 
  } 
}