I'm puzzled, yesterday I was able to get the five 7-segment leds to display the altitude the moment I changed the altitude in FSX but today there is a latency (5 seconds) between the value in FSX and the leds.

It also occurs on altitude active LED + any buttons I press.
I'm not sure where this latency might be coming from. Could it be a buffer overflow or something? Any ideas?

Here's the code I'm using:
#include "Wire.h"
#include "math.h"
#include "LedControl.h"
#include "Quadrature.h"


LedControl led_Display_1 = LedControl(12,11,10,5); // together running off of pins 12,11,10.
// pin 12 is connected to the DataIn
// pin 11 is connected to the CLK
// pin 10 is connected to LOAD


Quadrature quad1(8, 9);
int X;// a rotary variable
int Xold;// the old reading
int Xdif;// the difference since last loop
int active; // the mode thats active
int activeold;
int mark; // shows where the cursor is in the likes of ADF etc
int CodeIn; // used on all serial reads from Jim's code
String Digit; // Variable as a string to take from getChar()
int Count; // This variable used in loops in the EQUALS() function
int AP_alt_set[6]; // AP_alt_set[5] is an array of the 5 digits that are the Auto Pilot Altitude Set
int KpinNo;
int Koutpin;


String KoldpinStateSTR, KpinStateSTR, Kstringnewstate, Kstringoldstate;
String led_autopilot;


//**********************************************************
//*************( START of void setup() )********************


void setup()
{
Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";


for (int KoutPin = 3; KoutPin < 7; KoutPin++)// Get all the pins ready for "Keys"
{
pinMode(KoutPin, INPUT);
digitalWrite(KoutPin, HIGH);
}
pinMode(2, OUTPUT);
//pinMode(14, INPUT);


//The MAX72XX is in power-saving mode on startup, we have to do a wakeup call
delay (500);
led_Display_1.shutdown(0, false); // I have 4 displays, these start them up
//delay (500); // I put the delay in so they all dont start drawing
// led_Display_1.shutdown(1,false); // current at the same time.
// delay (500); // I had an issue with running on only USB power and getting a display glitch.
// led_Display_1.shutdown(2,false); // The delay seems to have fixed this issue.
// delay (500);
// led_Display_1.shutdown(3,false);


// Set the brightness to a lower than medium values
led_Display_1.setIntensity(0, ;
// led_Display_1.setIntensity(1,;
// led_Display_1.setIntensity(2,;
// led_Display_1.setIntensity(3,;


// and clear the display
led_Display_1.clearDisplay(0);
// led_Display_1.clearDisplay(1);
// led_Display_1.clearDisplay(2);
// led_Display_1.clearDisplay(3);


Serial.begin(115200);
}


void loop() {
{INPUTS();} // Check for any inputs

{ROTARYS();} // go and check the rotary encoder

if (Serial.available()) {
CodeIn = getChar();
if (CodeIn == '=') {
EQUALS(); // The first identifier is "="
}

if (CodeIn == '<') {
LESSTHAN(); // The first identifier is "<"
}

if (CodeIn == '?') {
QUESTION(); // The first identifier is "?"
}
if (CodeIn == '/') {
SLASH(); // The first identifier is "/" (Annunciators)
}
if (CodeIn == '#') {
POUND(); // the pound identifier is "#" (simconnect inputs)
}
}
}


char getChar()// Get a character from the serial buffer
{
while (Serial.available() == 0); // wait for data
return ((char)Serial.read()); // Thanks Doug
}


void EQUALS() // The first identifier was "="
{
CodeIn = getChar(); // Get another character
switch (CodeIn) // Now lets find what to do with it
{
case 'b': // AP altitude set
Count = 0; // clear the Count
while (Count < 6) // we will count to 5 from 0 to 4
{
Digit = ""; // clears the string variable Digit
Digit += getChar(); // Makes the string Digit what ever getChar() is holding


AP_alt_set[Count] = Digit.toInt(); // Turns the string Digit into an Integer and
// then stores it in the Array AP_alt_set[] 0,1,2,3,4
Count++;
}


led_Display_1.setDigit(0, 0, AP_alt_set[0], false); // First digit of Alt Set is displayed
led_Display_1.setDigit(0, 1, AP_alt_set[1], false); // Second digit of Alt Set is displayed
led_Display_1.setDigit(0, 2, AP_alt_set[2], false); // Third digit of Alt Set is displayed
led_Display_1.setDigit(0, 3, AP_alt_set[3], false); // Fourth digit of Alt Set is displayed
led_Display_1.setDigit(0, 4, AP_alt_set[4], false); // Fifth digit of Alt Set is displayed
led_Display_1.setDigit(0, 5, AP_alt_set[5], false); // Sixth digit of Alt Set is displayed
// false denotes NO decimal point
break;


case 'k':
led_autopilot = "";
led_autopilot += getChar();
if (led_autopilot == "1") {
digitalWrite(2, HIGH); //action the LED
} else {
digitalWrite(2, LOW);
}
break;
}
}


void LESSTHAN() { // The first identifier was "<"
}


void QUESTION() { // The first identifier was "?"
}


void SLASH() { // The first identifier was "/" (Annunciators)
}


void POUND() { // The first identifier was "#" (Annunciators)
}


void INPUTS()
{
Kstringnewstate = "";
for (int KpinNo = 3; KpinNo < 8; KpinNo++) { //set to the input pins. (pins 14 to 21 ,, change for Uno cards)
KpinStateSTR = String(digitalRead(KpinNo));
KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 3));// set to the first pin read (The 6)
if (KpinStateSTR != KoldpinStateSTR)// checks if it's different to the last reading of that pinNo
{
if (KpinNo == 3 && KpinStateSTR == "0") {
Serial.println ("B05"); //sets gear handle up
}


}//end of 'its different'
Kstringnewstate += KpinStateSTR;
}//end of 'for' loop (read the pins)
Kstringoldstate = Kstringnewstate;
}


void ROTARYS() {//now the bit for the rotary encoder input
X = (quad1.position() / 2);
if (X != Xold) { // checks to see if it different
(Xdif = (X - Xold)); // finds out the difference
//lcd.setCursor(0, 0);


if (Xdif == 1) {
Serial.println("B12");
}
if (Xdif == -1) {
Serial.println("B11");
}


if (quad1.position() > 1000) { // zero the rotary encoder count if too high or low
quad1.position(0);
}
if (quad1.position() < -1000) {
quad1.position(0);
}
Xold = X; // overwrites the old reading with the new one.
}
}