/*
                  IMPORTANT INFORMATION: 
  I never got to finish this task but this is as far as I got with it:

  - Created a library of 26 alphabet characters

  - Im currently in the process of building a string matrix out of my character matrix library with
    the stringBuilder() function.

  - Once the stringBuilder() function was working, the plan was to update the string to the LED array 
    in the same way I did in Pass Plus Q2, however this task is not currently in an 
    executable state. I'm not sure if the work that has been done thus far can get some concequential 
    marks therefore I thought I would include it just in case.
*/ 
int characterSelector = 1;
int columnMemory[8];
int length = 6;
int characters[6] = {1,17,0,13,10,14};
int columnLocation = 0;
int stringMatrix[56][8];
int library_display[26][8][8] = 
{
    //A
  {
    {0,0,0,1,1,0,0,0},
    {0,0,1,0,0,1,0,0},
    {0,1,0,0,0,0,1,0},
    {0,1,1,1,1,1,1,0},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1}
  },
    //B
  {
    {1,1,1,1,1,1,1,0},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,1,0},
    {1,1,1,1,1,1,1,0},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,1,1,1,1,1,1,0}
  },
    //C
  {
    {0,1,1,1,1,1,1,0},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {0,1,1,1,1,1,1,0} 
  },
    //D
  {
    {1,1,1,1,1,1,0,0},
    {1,0,0,0,0,0,1,0},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,1,0},
    {1,1,1,1,1,1,0,0} 
  },
    //E
  {
    {1,1,1,1,1,1,1,1},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,1,1,1,1,1,1,1},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,1,1,1,1,1,1,1} 
  }, 
    //F
  {
    {1,1,1,1,1,1,1,1},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,1,1,1,1,1,1,1},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0} 
  },
    //G
  {
    {0,1,1,1,1,1,1,0},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,0,0,1,1,1,1,1},
    {1,0,0,0,0,0,1,0},
    {0,1,1,1,1,1,0,0} 
  }, 
    //H
  {
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,1,1,1,1,1,1,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1} 
  },
    //I
  {
    {0,0,1,1,1,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,1,1,1,0,0,0} 
  },
    //J
  {
    {0,0,1,1,1,1,1,1},
    {0,0,0,0,0,0,1,0},
    {0,0,0,0,0,0,1,0},
    {0,0,0,0,0,0,1,0},
    {1,0,0,0,0,0,1,0},
    {1,0,0,0,0,0,1,0},
    {0,1,0,0,0,1,1,0},
    {0,0,1,1,1,0,0,0} 
  },
    //K
  {
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,1,0},
    {1,0,0,0,0,1,0,0},
    {1,1,1,1,1,0,0,0},
    {1,0,0,0,0,1,0,0},
    {1,0,0,0,0,0,1,0},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1} 
  },
    //L
  {
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,1,1,1,1,1,1,1} 
  },   
    //M
  {
    {1,0,0,0,0,0,0,1},
    {1,1,0,0,0,0,1,1},
    {1,0,1,0,0,1,0,1},
    {1,0,0,1,1,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1} 
  },  
    //N
  {
    {1,0,0,0,0,0,0,1},
    {1,1,0,0,0,0,0,1},
    {1,0,1,0,0,0,0,1},
    {1,0,0,1,0,0,0,1},
    {1,0,0,0,1,0,0,1},
    {1,0,0,0,0,1,0,1},
    {1,0,0,0,0,0,1,1},
    {1,0,0,0,0,0,0,1}  
  },   
    //O
  {
    {0,1,1,1,1,1,1,0},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {0,1,1,1,1,1,1,0} 
  }, 
    //P
  {
    {1,1,1,1,1,1,1,0},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,1,1,1,1,1,1,0},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0} 
  },
  //Q
  {
    {0,1,1,1,1,1,1,0},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,1,0,0,1},
    {1,0,0,0,0,1,1,0},
    {1,0,0,0,0,1,1,1},
    {0,1,1,1,1,0,0,1} 
  }, 
    //R
  {
    {1,1,1,1,1,1,1,0},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,1,1,1,1,1,1,0},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1} 
  },   
    //S
  {
    {0,1,1,1,1,1,1,1},
    {1,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0},
    {0,1,1,1,1,1,1,0},
    {0,0,0,0,0,0,0,1},
    {0,0,0,0,0,0,0,1},
    {0,0,0,0,0,0,0,1},
    {1,1,1,1,1,1,1,0} 
  },
    //T
  {
    {1,1,1,1,1,1,1,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0} 
  },
    //U
  {
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {0,1,1,1,1,1,1,0} 
  },
    //V
  {
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {0,1,0,0,0,0,1,0},
    {0,1,0,0,0,0,1,0},
    {0,0,1,0,0,1,0,0},
    {0,0,1,0,0,1,0,0},
    {0,0,0,1,1,0,0,0} 
  },
    //W
  {
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,0,0,0,0,1},
    {1,0,0,1,1,0,0,1},
    {1,0,1,0,0,1,0,1},
    {1,1,0,0,0,0,1,1},
    {1,0,0,0,0,0,0,1} 
  },
    //X
  {
    {1,0,0,0,0,0,0,1},
    {0,1,0,0,0,0,1,0},
    {0,0,1,0,0,1,0,0},
    {0,0,0,1,1,0,0,0},
    {0,0,0,1,1,0,0,0},
    {0,0,1,0,0,1,0,0},
    {0,1,0,0,0,0,1,0},
    {1,0,0,0,0,0,0,1} 
  },
    //Y
  {
    {1,0,0,0,0,0,1,0},
    {0,1,0,0,0,1,0,0},
    {0,0,1,0,1,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,0,1,0,0,0,0} 
  },
    //Z
  {
    {1,1,1,1,1,1,1,1},
    {0,0,0,0,0,0,1,0},
    {0,0,0,0,0,1,0,0},
    {0,0,0,0,1,0,0,0},
    {0,0,0,1,0,0,0,0},
    {0,0,1,0,0,0,0,0},
    {0,1,0,0,0,0,0,0},
    {1,1,1,1,1,1,1,1} 
  },
};
int pos;
int row;

void setup() {
  pos = 8;
  row = 7;
  Serial.begin(9600);
  for(int i = 2; i < 19; i++){
    pinMode(i, OUTPUT);
   digitalWrite(i, LOW); 
  }
  for(int i = 2; i < 10; i++){
   digitalWrite(i, HIGH); 
  }
  delay(1000);

}

int normalize(int i){                                // hasnt been updated yet but would have been tweaked to normalise matrixes of (x var) length                                        
  if (i > 8 )
  {
    i = i - 8;
  }
  return i;
}

void stringBuilder(string value)                              // merge characters into 1 string matrix for the display (unfinished)
{
  for (int k = 0; k < 8; k++)
  {
    for (int j = 0; j < ((value.length()* 8)+value.length()); j++)
    {
      for (int i = 0; i < 8; i++)
      {
        stringMatrix[k][i] = library_display[characters[j]][k][i];
        columnLocation++;    
      }
      stringMatrix[k][columnLocation] = 0; // adds a blank space between letters
    }
  }
}

void loop() {
 // put your main code here, to run repeatedly:
 stringBuilder();
 Serial.println(stringMatrix);
 
 for (int i = 0; i < 8; i++)                                 // hasnt been updated yet but would have been tweaked to display matrixes of (x var) length 
 {
   for (int delayer = 0; delayer < 100; delayer++)
  {
    digitalWrite(10,library_display[characterSelector][0][normalize(pos+i)]);
    digitalWrite(11,library_display[characterSelector][1][normalize(pos+i)]);
    digitalWrite(12,library_display[characterSelector][2][normalize(pos+i)]);
    digitalWrite(13,library_display[characterSelector][3][normalize(pos+i)]);
    digitalWrite(14,library_display[characterSelector][4][normalize(pos+i)]);
    digitalWrite(15,library_display[characterSelector][5][normalize(pos+i)]);
    digitalWrite(16,library_display[characterSelector][6][normalize(pos+i)]);
    digitalWrite(17,library_display[characterSelector][7][normalize(pos+i)]);
    digitalWrite((9 - pos ), LOW);
    digitalWrite((9 - pos ), HIGH); 
    delay(1);
    pos--;
    if (pos == -1) 
    {
      pos = 9;
      row++;
    }
  }
  delay(50);
 }  
}