Keeping my message displayed on the LCD after switch is released.

What I am trying to do is when I preset a momentary switch I want a MIDI command sent, an led turn on and all other LEDs to turn off and for it to display a message with button was pressed and keep that message displayed unit another button is pressed . I have the code working all but keeping the message of which button was pressed on the LCD screen after I release the button the message disappears. I understand the way I have it written the message will go away when I release the button. I am totally new at this and I am sure the code could look better or be written better but I understand it this way. So any help will be greatly appreciated. The whole project is going to be a 4 button MIDI foot controller for a Peavey Vypyr amp to just change between Bank A’s for presets which are 1 2 3 and 4 at the moment I have only setup 3. The LEDS on the pedal do tell me what preset is being used but I would like to actually have a display working so when I glance down I can see it as well. Like I said the program work with the amp like it should just having issue with the LCD part.

Here is my code.

#include <MIDI.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 7, 8, 9, 10);
const int BT1 = 2; // This is preset button 1
const int BT2 = 3; // This is preset button 2
const int BT3 = 4; // This is preset button 3
const int LED1 = 5; // This is LED for preset 1
const int LED2 = 6; // This is LED for preset 2
const int LED3 = 13; // This is LED for preset 3

void setup() {
pinMode (BT1, INPUT_PULLUP); //using internal pull down 10k resister to set BT1 to a high and as an input
pinMode (BT2, INPUT_PULLUP); //using internal pull down 10k resister to set BT2 to a high and as an input
pinMode (BT3, INPUT_PULLUP);
pinMode(LED1, OUTPUT); // Making LED1 pin 12 as an output
pinMode(LED2, OUTPUT); // Making LED2 pin 12 as an output
pinMode(LED3, OUTPUT);
Serial.begin(31250); // MIDI Baud rate is 31250 and using TX as the data out to the amp
}

void loop() {
int stateBT1 = digitalRead(BT1); //reading the intial state of BT1
int stateBT2 = digitalRead(BT2); // reading the intial state of BT2
int stateBT3 = digitalRead(BT3);
lcd.begin(16, 2);
lcd.print(“BANK A”);

// Preset 1
if (stateBT1 == 0) { // stating if the state of BT1 goes low then execute the below MIDI command and set the proper LEDS if BT1 is still high do nothing
Serial.write(0x90); //preset 1 note on
Serial.write(0x05);
Serial.write(0x7F);
Serial.write(0x90); //preset 1note off
Serial.write(0x05);
Serial.write(0x00);
digitalWrite(LED1, HIGH); //Turns on LED 1
digitalWrite(LED2, LOW); // Makes sure LED 2 is off
digitalWrite(LED3, LOW); // Makes sure LED 3 is off
lcd.setCursor(0,1);
lcd.print(“Preset 1”);
}

else {
// nothing is done here do not want to release of BT1 to execute anything
}

// Preset 2
if (stateBT2 == 0) { // stating if the state of BT2 goes low then execute the below MIDI command and set the proper LEDS if BT2 is still high do nothing
Serial.write(0x90); //preset 2 Note on
Serial.write(0x04);
Serial.write(0x7F);
Serial.write(0x90); //preset 2 Note off
Serial.write(0x04);
Serial.write(0x00);
digitalWrite(LED2, HIGH);
digitalWrite(LED1, LOW);
digitalWrite(LED3, LOW);
lcd.setCursor(0,1);
lcd.print(“Preset 2”);
}
else {
// nothing is done here do not want to release of BT2 to execute anything
}
// Preset 3
if (stateBT3 == 0) { // stating if the state of BT3 goes low then execute the below MIDI command and set the proper LEDS if BT2 is still high do nothing
Serial.write(0x90); //preset 3 Note on
Serial.write(0x09);
Serial.write(0x7F);
Serial.write(0x90); //preset 3 Note off
Serial.write(0x09);
Serial.write(0x00);
digitalWrite(LED3, HIGH);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
lcd.setCursor(0,1);
lcd.print(“Preset 3”);
}

else {
// nothing is done here do not want to release of BT2 to execute anything
}

delay(500);
}

You need to display the message when the button becomes pressed rather than when it is pressed. Look at the StateChangeDetection example in the IDE

Thanks I will play around with that I want to learn more but I was able to get it working with an if command outside the fist if functions. When I was adding them inside it would turn them off after I released the button. After I moved them it worked correctly. Like I said it may not be the right way of best way but it worked and I am happy with that. I will check out your way as well so I can learn. Thanks for your replay I appreciate it. I actually tied it to when the corresponding LED output went high to print to the LCD and with it out side of the main loop it worked.

The line "lcd.begin(16, 2);" in the "loop()" method should only be invoked once so you should move that to the "setup()" method. The second thing is not to update the display for each loop, but only when the content on the display changes.