I'll continue too debug and post later. in the mean time, I did find this code for someone who wants to go overboard with LCD and it supposedly reduces latency but I dont even experience latency.
#include <arduino2.h>
#include <pins2_arduino.h>
/* 4/2/16 this works with no delay
LiquidCrystal Library - setCursor
LiquidCrystal declaration:
LiquidCrystal lcd(RS,Enable,D4,D5,D6,D7)
The circuit:
1 Ground
2 5 Volts (VCC)
3 Display Contrast (VO) - to 10kohm potentiometer wiper (pin 2)
4 Register Select (RS) - controls whether writing to data register or instruction register. Command (0) or Character (1). Attached to digital pin (see above).
5 Read/Write (RW) - Selects reading mode or writing mode. optional, can attach to ground per LiquidCrystal() description on Arduino.cc and Wikipedia. Write (0) or Read (1). Attached to ground.
6 Enable (E) Attached to digital pin (see above).
7 Data Bit 0 (Not used in 4-bit operation) Open
8 Data Bit 1 (Not used in 4-bit operation) Open
9 Data Bit 2 (Not used in 4-bit operation) Open
10 Data Bit 3 (Not used in 4-bit operation) Open
11 Data Bit 4 attached to digital pin (see above)
12 Data Bit 5 attached to digital pin (see above)
13 Data Bit 6 attached to digital pin (see above)
14 Data Bit 7 attached to digital pin (see above)
15 LED Backlight Anode + to 220ohm resistor to 5 Volt
16 LED Backlight Cathode - to Ground
The Pot: (front view?)
O
1 2 3
1 goes to ground
2 (wiper) goes to VO
3 goes to 5V
(hopefully this is not reversed)
MIDI
Female output from inside:
O
14253
* MIDI jack pin 4 connected to +5V through 220-ohm resistor
* MIDI jack pin 2 connected to ground
* MIDI jack pin 5 to digital in 1 connected
*/
#include <LiquidCrystal.h>
//Pedals: Low C through High C
#define SWITCH1 30
#define SWITCH2 31
#define SWITCH3 32
#define SWITCH4 33
#define SWITCH5 34
#define SWITCH6 35
#define SWITCH7 36
#define SWITCH8 37
#define SWITCH9 38
#define SWITCH10 39
#define SWITCH11 40
#define SWITCH12 41
#define SWITCH13 42
#define PEDALBOUNCE 20
//Buttons will be: Select_Panic, SELECT_RIGHT, SELECT_UP, SELECT_DOWN
#define Select_Panic A0
#define Select_Right A1
#define Select_Up A2
#define Select_Down A3
#define BUTTONBOUNCE 300
int Buttons[17] = {SWITCH1, SWITCH2, SWITCH3, SWITCH4, SWITCH5, SWITCH6, SWITCH7, SWITCH8, SWITCH9, SWITCH10, SWITCH11, SWITCH12, SWITCH13, Select_Panic, Select_Right, Select_Up, Select_Down};
int ButtonState[17] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
int currentButton = 0;
int currentButtonState;
int TriggeredNote[13] = {36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48};
unsigned long stopTime;
boolean breakLoop;
//string arrays
const String LCDNoteName[12] = {"C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B "};
const String LCDNoteOctave[11] = {" 0", "1 ", "2 ", "3 ", "4 ", "5 ", "6 ", "7 ", "8 ", "9 ", "10"};
//LCD Initial Values: Volume - 0-127, Program - 0-127, Channel - 1-16, LowNote - 000(C0)-127(GC10)
byte Volume = 100;
byte Program = 0;
byte Channel = 0;
byte LowNote = 24; //C2
byte LowNoteName = 0; //C or LowNote%12
byte LowNoteOctave = 2; //Octave 2 or LowNote/12
// LCD dimensions
const int numRows = 2;
const int numCols = 16;
//Cursor Position: 1-Volume 2-Program 3-Channel 4-Low Note
int CursorPosition = 1;
// initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(14,15,16,17,18,19);
void Right() {
switch (CursorPosition) {
case 1:
lcd.setCursor(4, 1);
CursorPosition = 2;
break;
case 2:
lcd.setCursor(8, 1);
CursorPosition = 3;
break;
case 3:
lcd.setCursor(12, 1);
CursorPosition = 4;
break;
case 4:
lcd.setCursor(0, 1);
CursorPosition = 1;
break;
}
}
void Up() {
switch (CursorPosition) {
case 1:
if (Volume < 127)
Volume += 1;
if (Volume < 10) {
lcd.print("00");
}
else {
if (Volume < 100) {
lcd.print("0");
}
}
lcd.print(Volume, DEC);
lcd.setCursor(0, 1);
break;
case 2:
if (Program < 127)
Program += 1;
if (Program < 10) {
lcd.print("00");
}
else {
if (Program < 100) {
lcd.print("0");
}
}
lcd.print(Program, DEC);
lcd.setCursor(4, 1);
Serial.write(0xc0 + Channel);
Serial.write(Program);
break;
case 3:
if (Channel < 15)
Channel += 1;
lcd.print("0");
if (Channel < 9) {
lcd.print("0");
}
lcd.print(Channel + 1, DEC);
lcd.setCursor(8, 1);
break;
case 4:
if (LowNote < 127)
LowNote += 1;
for (int Counter = 0; Counter <= 13; Counter++) {
TriggeredNote[Counter]++;
}
LowNoteName = LowNote % 12;
LowNoteOctave = LowNote / 12;
lcd.print (LCDNoteName[LowNoteName] + LCDNoteOctave[LowNoteOctave]);
lcd.setCursor(12, 1);
break;
}
}
void Down() {
switch (CursorPosition) {
case 1:
if (Volume > 0)
Volume -= 1;
if (Volume < 10) {
lcd.print("00");
}
else {
if (Volume < 100) {
lcd.print("0");
}
}
lcd.print(Volume, DEC);
lcd.setCursor(0, 1);
break;
case 2:
if (Program > 0)
Program -= 1;
if (Program < 10) {
lcd.print("00");
}
else {
if (Program < 100) {
lcd.print("0");
}
}
lcd.print(Program, DEC);
lcd.setCursor(4, 1);
Serial.write(0xc0 + Channel);
Serial.write(Program);
break;
case 3:
if (Channel > 0)
Channel -= 1;
lcd.print("0");
if (Channel < 9) {
lcd.print("0");
}
lcd.print(Channel + 1, DEC);
lcd.setCursor(8, 1);
break;
case 4:
if (LowNote > 0)
LowNote -= 1;
for (int Counter = 0; Counter <= 13; Counter++) {
TriggeredNote[Counter]--;
}
LowNoteName = LowNote % 12;
LowNoteOctave = LowNote / 12;
lcd.print (LCDNoteName[LowNoteName] + LCDNoteOctave[LowNoteOctave]);
lcd.setCursor(12, 1);
break;
}
}
void Panic()
{ for (int Counter = 0; Counter <= 15; Counter++) {
Serial.write(176 + Counter);
Serial.write(123);
Serial.write(0);
}
}
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}
void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
// set up the LCD's number of columns and rows:
lcd.begin(numCols, numRows);
lcd.setCursor(0, 0);
lcd.print("VOL PRG CHN LOW");
lcd.setCursor(0, 1);
lcd.print("100 000 001 C 2");
lcd.setCursor(0, 1);
lcd.cursor();
//set up buttons
for ( currentButton = 0; currentButton < 17; currentButton++ ) {
pinMode2( Buttons[currentButton], INPUT ); // Set pin for switch
digitalWrite2( Buttons[currentButton], HIGH ); // Turn on internal pullup
}
}
void loop() {
while (true) {
breakLoop = false;
while (breakLoop == false) {
for ( currentButton = 0; currentButton < 17; currentButton++ ) {
currentButtonState = digitalRead2(Buttons[currentButton]);
if (currentButton < 13) {
{
if (currentButtonState != ButtonState[currentButton] ) {
if ( ButtonState[currentButton] == LOW ) {
noteOn(0x80 + Channel, TriggeredNote[currentButton], 0x00);
ButtonState[currentButton] = HIGH;
}
else
{ noteOn(0x90 + Channel, TriggeredNote[currentButton], Volume);
ButtonState[currentButton] = LOW;
}
stopTime = millis() + PEDALBOUNCE;
while (millis() < stopTime) {};
}
}
if (currentButton == 13 && currentButtonState == LOW) {
Panic();
stopTime = millis() + BUTTONBOUNCE;
while (millis() < stopTime) {};
}
if (currentButton > 13 && currentButtonState == LOW) {
breakLoop = true;
stopTime = millis() + BUTTONBOUNCE;
while (millis() < stopTime) {};
}
}
}
breakLoop = false;
while (breakLoop == false) {
for ( currentButton = 0; currentButton < 17; currentButton++ ) {
currentButtonState = digitalRead2(Buttons[currentButton]);
if (currentButton < 13 && currentButtonState == LOW) {
breakLoop = true;
stopTime = millis() + PEDALBOUNCE;
while (millis() < stopTime) {};
}
if (currentButton == 13 && currentButtonState == LOW) {
Panic();
stopTime = millis() + BUTTONBOUNCE;
while (millis() < stopTime) {};
}
if (currentButton == 14 && currentButtonState == LOW) {
Right();
stopTime = millis() + BUTTONBOUNCE;
while (millis() < stopTime) {};
}
if (currentButton == 15 && currentButtonState == LOW) {
Up();
stopTime = millis() + BUTTONBOUNCE;
while (millis() < stopTime) {};
}
if (currentButton == 16 && currentButtonState == LOW) {
Down();
stopTime = millis() + BUTTONBOUNCE;
while (millis() < stopTime) {};
}
}
}
}
}
}