Hi, i'm trying to make a midi controller for a Kemper Profiler that shows the rig name and slot name on a 16x2 lcd screen, i don't know any programming, so i've been using google to find codes and then trial and error, i also used chatgpt to help me understand some stuff.
So far this is my code, i managed to make the arduino (leonardo) send and receive sysex messages and show the receiven message on the screen (thos would be the slot and performance names) but for some reason everything is showing in the first row of the screen. This is the latest code i'm trying, it shows the performance and slot names when i press the buttons but on the first row only, and it shows the words "slot name" in the second row.
I have no idea how to make it work as intended, i tried lcd.setCursor but for some reason it's not working...
#include <Control_Surface.h>
#include <USB-MIDI.h>
#include <Wire.h>
#include <hd44780.h> // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
hd44780_I2Cexp lcd;
// Instantiate the MIDI over USB interface
USBMIDI_Interface myMIDI;
const int LCD_COLS = 16;
const int LCD_ROWS = 2;
// Custom MIDI callback that prints incoming SysEx messages.
struct MyMIDI_Callbacks : MIDI_Callbacks {
// This callback function is called when a SysEx message is received.
void onSysExMessage(MIDI_Interface &interface, SysExMessage sysex) override {
// Check if the message is from the USB MIDI interface
if (&interface != &myMIDI) return;
// Define variables to keep track of parsing state
String currentName;
// Iterate through the received SysEx message starting from the 6th byte
for (int i = 6; i < sysex.length - 1; ++i) {
uint8_t byte = sysex.data[i];
// Check if the byte is within the printable ASCII range
if (byte >= 0x20 && byte <= 0x7E) {
currentName += char(byte);
}
}
// Calculate the starting position to center the name on the LCD
int startPosition = max(0, (LCD_COLS - currentName.length()) / 2);
// Clear the LCD
lcd.clear();
// Print the performance name at the top (first row)
lcd.setCursor(0, 0); // Set cursor to the first row
lcd.print(currentName);
Serial.println("Performance Name displayed: " + currentName); // Debugging statement
// Print the slot name at the bottom (second row)
lcd.setCursor(0, 1); // Set cursor to the second row
lcd.print("Slot Name"); // Change "Slot Name" to the actual slot name variable
}
} callback {};
USBMIDI_CREATE_DEFAULT_INSTANCE();
const int buttonPin = {0};
const int buttonPin2 = {13};
const int buttonPin3 = {4};
const int buttonPin4 = {5};
const int buttonPin5 = {6};
const int buttonPin6 = {7};
const int buttonPin7 = {8};
const int buttonPin8 = {9};
const int buttonPin9 = {10};
const int buttonPin10 = {11};
const int buttonPin11 = {12};
int buttonState = 0;
int lastButtonState = 0;
int toggleState = 0;
int buttonState2 = 0;
int lastButtonState2 = 0;
int toggleState2 = 0;
int buttonState3 = 0;
int lastButtonState3 = 0;
int toggleState3 = 0;
int buttonState4 = 0;
int lastButtonState4 = 0;
int toggleState4 = 0;
int buttonState5 = 0;
int lastButtonState5 = 0;
int toggleState5 = 0;
int buttonState6 = 0;
int lastButtonState6 = 0;
int toggleState6 = 0;
int buttonState7 = 0;
int lastButtonState7 = 0;
int toggleState7 = 0;
int buttonState8 = 0;
int lastButtonState8 = 0;
int toggleState8 = 0;
int buttonState9 = 0;
int lastButtonState9 = 0;
int toggleState9 = 0;
int buttonState10 = 0;
int lastButtonState10 = 0;
int toggleState10 = 0;
int buttonState11 = 0;
int lastButtonState11 = 0;
int toggleState11 = 0;
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void setup()
{
Serial.begin(31250);
Wire.begin();
lcd.begin(LCD_COLS, LCD_ROWS);
lcd.clear();
delay(1000);
myMIDI.begin();
MIDI.begin(MIDI_CHANNEL_OMNI);
// Inicialización de pines de botones
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(buttonPin4, INPUT_PULLUP);
pinMode(buttonPin5, INPUT_PULLUP);
pinMode(buttonPin6, INPUT_PULLUP);
pinMode(buttonPin7, INPUT_PULLUP);
pinMode(buttonPin8, INPUT_PULLUP);
pinMode(buttonPin9, INPUT_PULLUP);
pinMode(buttonPin10, INPUT_PULLUP);
pinMode(buttonPin11, INPUT_PULLUP);
// MIDI interface initialization is successful if it reached here
// Set MIDI callbacks
myMIDI.setCallbacks(callback);
Serial.println("Setup completed."); // Indicate setup completion
// Request performance name
uint8_t sysexPerformanceStartup[] = {0xF0, 0x00, 0x20, 0x33, 0x00, 0x00, 0x47, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF7};
myMIDI.sendSysEx(sysexPerformanceStartup);
Serial.println("Requesting performance name...");
// Request slot name
uint8_t sysexSlotStartup[] = {0xF0, 0x00, 0x20, 0x33, 0x02, 0x7F, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF7};
myMIDI.sendSysEx(sysexSlotStartup);
Serial.println("Requesting slot name...");
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void loop() {
buttonState = digitalRead(buttonPin);
if(buttonState != lastButtonState && buttonState == 1 && toggleState == 0) {
MIDI.sendControlChange(22, 127, 1);
//MIDI.sendControlChange(99, 58, 1);
//MIDI.sendControlChange(98, 3, 1);
//MIDI.sendControlChange(6, 1, 1);
//MIDI.sendControlChange(38, 1, 1);
toggleState = 1;
delay(300);
}
else if(buttonState != lastButtonState && buttonState == 1 && toggleState == 1) {
MIDI.sendControlChange(22, 0, 1);
toggleState = 0;
delay(300);
}
lastButtonState = buttonState;
buttonState2 = digitalRead(buttonPin2);
if(buttonState2 != lastButtonState2 && buttonState2 == 1 && toggleState2 == 0) {
MIDI.sendControlChange(24, 127, 1);
toggleState2 = 1;
delay(300);
}
else if(buttonState2 != lastButtonState2 && buttonState2 == 1 && toggleState2 == 1) {
MIDI.sendControlChange(24, 0, 1);
toggleState2 = 0;
delay(300);
}
lastButtonState2 = buttonState2;
buttonState3 = digitalRead(buttonPin3);
if(buttonState3 != lastButtonState3 && buttonState3 == 1 && toggleState3 == 0) {
MIDI.sendControlChange(27, 127, 1);
toggleState3 = 1;
delay(300);
}
else if(buttonState3 != lastButtonState3 && buttonState3 == 1 && toggleState3 == 1) {
MIDI.sendControlChange(27, 0, 1);
toggleState3 = 0;
delay(300);
}
lastButtonState3 = buttonState3;
buttonState4 = digitalRead(buttonPin4);
if(buttonState4 != lastButtonState4 && buttonState4 == 1 && toggleState4 == 0) {
MIDI.sendControlChange(28, 127, 1);
toggleState4 = 1;
delay(300);
}
else if(buttonState4 != lastButtonState4 && buttonState4 == 1 && toggleState4 == 1) {
MIDI.sendControlChange(28, 0, 1);
toggleState4 = 0;
delay(300);
}
lastButtonState4 = buttonState4;
buttonState5 = digitalRead(buttonPin5);
if(buttonState5 != lastButtonState5 && buttonState5 == 1 && toggleState5 == 0) {
MIDI.sendControlChange(31, 127, 1);
toggleState5 = 1;
delay(300);
}
else if(buttonState5 != lastButtonState5 && buttonState5 == 1 && toggleState5 == 1) {
MIDI.sendControlChange(31, 0, 1);
toggleState5 = 0;
delay(300);
}
lastButtonState5 = buttonState5;
// Send a SysEx message when the button for slot name is pressed
uint8_t sysexSlot[] = {0xF0, 0x00, 0x20, 0x33, 0x02, 0x7F, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF7};
buttonState6 = digitalRead(buttonPin6);
if(buttonState6 != lastButtonState6 && buttonState6 == 1 && toggleState6 == 0) {
MIDI.sendControlChange(50, 1, 1);
toggleState6 = 1;
// Send the SysEx message
myMIDI.sendSysEx(sysexSlot);
Serial.println(":"); // Print slot name
lcd.print(""); // Print slot name
Serial.println("SysEx message for slot name sent.");
delay(300);
}
// Reset the flag when the button is released
else if(buttonState6 != lastButtonState6 && buttonState6 == 1 && toggleState6 == 1) {
MIDI.sendControlChange(50, 1, 1);
myMIDI.sendSysEx(sysexSlot);
Serial.println(":"); // Print slot name
lcd.print(""); // Print slot name
Serial.println("SysEx message for slot name sent.");
toggleState6 = 0;
delay(300);
// messageSent = false;
}
lastButtonState6 = buttonState6;
// Send a SysEx message when the button for slot name is pressed
uint8_t sysexSlot2[] = {0xF0, 0x00, 0x20, 0x33, 0x02, 0x7F, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF7};
buttonState7 = digitalRead(buttonPin7);
if(buttonState7 != lastButtonState7 && buttonState7 == 1 && toggleState7 == 0) {
MIDI.sendControlChange(51, 1, 1);
myMIDI.sendSysEx(sysexSlot2);
Serial.println(""); // Print slot name
lcd.print(""); // Print slot name
Serial.println("SysEx message for slot name sent.");
delay(300);
}
else if(buttonState7 != lastButtonState7 && buttonState7 == 1 && toggleState7 == 1) {
MIDI.sendControlChange(51, 1, 1);
myMIDI.sendSysEx(sysexSlot2);
Serial.println(":"); // Print slot name
lcd.print(""); // Print slot name
Serial.println("SysEx message for slot name sent.");
toggleState7 = 0;
delay(300);
}
lastButtonState7 = buttonState7;
// Send a SysEx message when the button for slot name is pressed
uint8_t sysexSlot3[] = {0xF0, 0x00, 0x20, 0x33, 0x02, 0x7F, 0x43, 0x00, 0x00, 0x01, 0xF7};
buttonState8 = digitalRead(buttonPin8);
if(buttonState8 != lastButtonState8 && buttonState8 == 1 && toggleState8 == 0) {
MIDI.sendControlChange(52, 1, 1);
myMIDI.sendSysEx(sysexSlot3);
lcd.print(""); // Print slot name
Serial.println("SysEx message for slot name sent.");
delay(300);
}
else if(buttonState8 != lastButtonState8 && buttonState8 == 1 && toggleState8 == 1) {
MIDI.sendControlChange(52, 1, 1);
myMIDI.sendSysEx(sysexSlot3);
lcd.print(""); // Print slot name
Serial.println("SysEx message for slot name sent.");
toggleState8 = 0;
delay(300);
}
lastButtonState8 = buttonState8;
// Send a SysEx message when the button for slot name is pressed
uint8_t sysexSlot4[] = {0xF0, 0x00, 0x20, 0x33, 0x02, 0x7F, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF7};
buttonState9 = digitalRead(buttonPin9);
if(buttonState9 != lastButtonState9 && buttonState9 == 1 && toggleState9 == 0) {
MIDI.sendControlChange(53, 1, 1);
myMIDI.sendSysEx(sysexSlot4);
lcd.print(""); // Print slot name
Serial.println("SysEx message for slot name sent.");
delay(300);
}
else if(buttonState9 != lastButtonState9 && buttonState9 == 1 && toggleState9 == 1) {
MIDI.sendControlChange(53, 1, 1);
myMIDI.sendSysEx(sysexSlot4);
lcd.print(""); // Print slot name
Serial.println("SysEx message for slot name sent.");
toggleState9 = 0;
delay(300);
}
lastButtonState9 = buttonState9;
// Send a SysEx message when the button for performance name is pressed
uint8_t sysexPerformance[] = {0xF0, 0x00, 0x20, 0x33, 0x00, 0x00, 0x47, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF7};
buttonState10 = digitalRead(buttonPin10);
if(buttonState10 != lastButtonState10 && buttonState10 == 1 && toggleState10 == 0) {
MIDI.sendControlChange(49,0, 1);
myMIDI.sendSysEx(sysexPerformance);
lcd.print(""); // Print perfornamce name
Serial.println("SysEx message for performance name sent.");
toggleState11 = 1;
delay(300);
}
else if(buttonState10 != lastButtonState10 && buttonState10 == 1 && toggleState10 == 1) {
MIDI.sendControlChange(49, 0, 1);
myMIDI.sendSysEx(sysexPerformance);
lcd.print(""); // Print perfornamce name
Serial.println("SysEx message for performance name sent.");
lastButtonState10 = buttonState10;
toggleState10 = 0;
delay(300);
}
lastButtonState10 = buttonState10;
buttonState11 = digitalRead(buttonPin11);
// Send a SysEx message when the button for performance name is pressed
uint8_t sysexPerformance2[] = {0xF0, 0x00, 0x20, 0x33, 0x00, 0x00, 0x47, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF7};
if(buttonState11 != lastButtonState11 && buttonState11 == 1 && toggleState11 == 0) {
MIDI.sendControlChange(48, 0, 1);
myMIDI.sendSysEx(sysexPerformance2);
lcd.print(""); // Print performance name
Serial.println("SysEx message for performance name sent.");
lastButtonState11 = buttonState11;
toggleState11 = 1;
delay(300);
}
else if(buttonState11 != lastButtonState11 && buttonState11 == 1 && toggleState11 == 1) {
MIDI.sendControlChange(48, 0, 1);
myMIDI.sendSysEx(sysexPerformance2);
lcd.print(""); // Print performance name
Serial.println("SysEx message for performance name sent.");
toggleState11 = 0;
delay(300);
}
lastButtonState11 = buttonState11;
myMIDI.update();
}
I home someone knows how i could make it work and is willing to help, as i said, i'm pretty new to this so i have no idea what i'm doing ![]()
Thanks!