#define numMax7219 4 // Modifica il numero in base al tuo setup

byte matrice [8][8];
bool fraseProcessed = false;
bool fraseInserita = false;
char inputArray[100];

// Pin DI USCITA
#define CS 9  // Chip-Select
#define CLK 10 // Clock
#define DIN 11 // Data-Input

// Variabili
/*byte matrice[][8] = {(B00111100),
                     (B01100010),
                     (B01100000),
                     (B01111100),
                     (B01100110),
                     (B01100110),
                     (B01100110),
                     (B00111100)};*/



const uint8_t charMatrix[][8] = {
  {B00110000, B01111000, B11001100, B11001100, B11111100, B11001100, B11001100, B00000000}, // A
  {B11111100, B01100110, B01100110, B01111100, B01100110, B01100110, B11111100, B00000000}, // B
  {B00111100, B01100110, B01000000, B01000000, B01000000, B01100110, B00111100, B00000000}, // C
  {B11111000, B01101100, B01100110, B01100110, B01100110, B01101100, B11111000, B00000000}, // D
  {B11111110, B01100010, B01101000, B01111000, B01101000, B01100010, B11111110, B00000000}, // E
  {B11111110, B01100010, B01101000, B01111000, B01101000, B01100000, B11110000, B00000000}, // F
  {B00111100, B01100110, B11000000, B11000000, B11001110, B01100110, B00111110, B00000000}, // G
  {B11001100, B11001100, B11001100, B11111100, B11001100, B11001100, B11001100, B00000000}, // H
  {B01111000, B00110000, B00110000, B00110000, B00110000, B00110000, B01111000, B00000000}, // I
  {B00011110, B00001100, B00001100, B00001100, B11001100, B11001100, B01111000, B00000000}, // J
  {B11110110, B01100110, B01101100, B01111000, B01101100, B01100110, B11110110, B00000000}, // K
  {B11110000, B01100000, B01100000, B01100000, B01100010, B01100110, B11111110, B00000000}, // L
  {B11000110, B11101110, B11111110, B11111110, B11010110, B11000110, B11000110, B00000000}, // M
  {B11000110, B11100110, B11110110, B11011110, B11001110, B11000110, B11000110, B00000000}, // N
  {B00111000, B01101100, B11000110, B11000110, B11000110, B01101100, B00111000, B00000000}, // O
  {B11111100, B01100110, B01100110, B01111100, B01100000, B01100000, B11110000, B00000000}, // P
  {B01111000, B11001100, B11001100, B11001100, B11011100, B01111000, B00011100, B00000000}, // Q
  {B11111100, B01100110, B01100110, B01111100, B01101100, B01100110, B11110110, B00000000}, // R
  {B01111000, B11001100, B11100000, B01110000, B00011100, B11001100, B01111000, B00000000}, // S
  {B11111100, B10110100, B00110000, B00110000, B00110000, B00110000, B01111000, B00000000}, // T
  {B11001100, B11001100, B11001100, B11001100, B11001100, B11001100, B11111100, B00000000}, // U
  {B11001100, B11001100, B11001100, B11001100, B11001100, B01111000, B00110000, B00000000}, // V
  {B11000110, B11000110, B11000110, B11010110, B11111110, B11101110, B11000110, B00000000}, // W
  {B11000110, B11000110, B01101100, B00111000, B00111000, B01101100, B11000110, B00000000}, // X
  {B11001100, B11001100, B11001100, B01111000, B00110000, B00110000, B01111000, B00000000}, // Y
  {B11111110, B11000110, B10001100, B00011000, B00110010, B01100110, B11111110, B00000000}, // Z
  {B00000000, B00000000, B01111000, B00001100, B01111100, B11001100, B01110110, B00000000}, // a
  {B11100000, B01100000, B01100000, B01111100, B01100110, B01100110, B11011100, B00000000}, // b
  {B00000000, B00000000, B01111000, B11001100, B11000000, B11001100, B01111000, B00000000}, // c
  {B00011100, B00001100, B00001100, B01111100, B11001100, B11001100, B01110110, B00000000}, // d
  {B00000000, B00000000, B01111000, B11001100, B11111100, B11000000, B01111000, B00000000}, // e
  {B00111000, B01101100, B01100000, B11110000, B01100000, B01100000, B11110000, B00000000}, // f
  {B00000000, B00000000, B01110110, B11001100, B11001100, B01111100, B00001100, B11111000}, // g
  {B11100000, B01100000, B01101100, B01110110, B01100110, B01100110, B11100110, B00000000}, // h
  {B00110000, B00000000, B01110000, B00110000, B00110000, B00110000, B01111000, B00000000}, // i
  {B00001100, B00000000, B00001100, B00001100, B00001100, B11001100, B11001100, B01111000}, // j
  {B11100000, B01100000, B01100110, B01101100, B01111000, B01101100, B11100110, B00000000}, // k
  {B01110000, B00110000, B00110000, B00110000, B00110000, B00110000, B01111000, B00000000}, // l
  {B00000000, B00000000, B11001100, B11111110, B11111110, B11010110, B11000110, B00000000}, // m
  {B00000000, B00000000, B11111000, B11001100, B11001100, B11001100, B11001100, B00000000}, // n
  {B00000000, B00000000, B01111000, B11001100, B11001100, B11001100, B01111000, B00000000}, // o
  {B00000000, B00000000, B11011100, B01100110, B01100110, B01111100, B01100000, B11110000}, // p
  {B00000000, B00000000, B01110110, B11001100, B11001100, B01111100, B00001100, B00011110}, // q
  {B00000000, B00000000, B10011100, B01110110, B01100110, B01100000, B11110000, B00000000}, // r
  {B00000000, B00000000, B01111100, B11000000, B01111000, B00001100, B11111000, B00000000}, // s
  {B00010000, B00110000, B01111100, B00110000, B00110000, B00110100, B00011000, B00000000}, // t
  {B00000000, B00000000, B11001100, B11001100, B11001100, B11001100, B01110110, B00000000}, // u
  {B00000000, B00000000, B11001100, B11001100, B11001100, B01111000, B00110000, B00000000}, // v
  {B00000000, B00000000, B11000110, B11000110, B11010110, B11111110, B01101100, B00000000}, // w
  {B00000000, B00000000, B11000110, B01101100, B00111000, B01101100, B11000110, B00000000}, // x
  {B00000000, B00000000, B11001100, B11001100, B11001100, B01111100, B00001100, B11111000}, // y
  {B00000000, B00000000, B11111100, B10011000, B00110000, B01100100, B11111100, B00000000}, // z
  {B01111000, B11001100, B11011100, B11111100, B11101100, B11001100, B01111100, B00000000}, // 0
  {B00110000, B01110000, B00110000, B00110000, B00110000, B00110000, B11111100, B00000000}, // 1
  {B01111000, B11001100, B00001100, B00111000, B01100000, B11001100, B11111100, B00000000}, // 2
  {B01111000, B11001100, B00001100, B00111000, B00001100, B11001100, B01111000, B00000000}, // 3
  {B00011100, B00111100, B01101100, B11001100, B11111110, B00001100, B00011110, B00000000}, // 4
  {B11111100, B11000000, B11111000, B00001100, B00001100, B11001100, B01111000, B00000000}, // 5
  {B00111000, B01100000, B11000000, B11111000, B11001100, B11001100, B01111000, B00000000}, // 6
  {B11111100, B11001100, B00001100, B00011000, B00110000, B00110000, B00110000, B00000000}, // 7
  {B01111000, B11001100, B11001100, B01111000, B11001100, B11001100, B01111000, B00000000}, // 8
  {B01111000, B11001100, B11001100, B01111100, B00001100, B00011000, B01110000, B00000000}, // 9
  {B00110000, B01111000, B01111000, B00110000, B00110000, B00000000, B00110000, B00000000}, // !
  {B01101100, B01101100, B11111110, B01101100, B11111110, B01101100, B01101100, B00000000}, // #
  {B00110000, B01111100, B11000000, B01111000, B00001100, B11111000, B00110000, B00000000}, // $
  {B00000000, B11000110, B11001100, B00011000, B00110000, B01100110, B11000110, B00000000}, // %
  {B00111000, B01101100, B00111000, B01110110, B11011100, B11001100, B01110110, B00000000}, // &
  {B01111000, B11001100, B00001100, B00011000, B00110000, B00000000, B00110000, B00000000}  // ?
  };


unsigned long int deltaT = 80; // Tempo di ritardo CLK

void setup()
{
  Serial.begin(9600);
  pinMode(CS, OUTPUT);
  pinMode(CLK, OUTPUT);
  pinMode(DIN, OUTPUT);
  digitalWrite(CS, HIGH);
  digitalWrite(CLK, LOW);
  digitalWrite(DIN, LOW);

  // Inizializza MAX7219
  sendCommand(0x0C, 0x01); // Normal operation
  sendCommand(0x09, 0x00); // NO DECODE
  sendCommand(0x0F, 0x00); // NO Lamp TEST
  sendCommand(0x0B, 0x07); // Normal operation
  sendCommand(0x0A, 0x08); // Intensity 8
  sendCommand(0x0C, 0x01); // Normal operation
  Serial.println("Inserisci un carattere:");
}

void loop() {

  if (!fraseProcessed && Serial.available() > 0) {
        leggiFrase(); // Leggi la frase in input dall'utente
        fraseProcessed = true;
    }

if (fraseProcessed) {
    // Itera attraverso ogni carattere della frase e stampalo
    for (int i = 0; i < strlen(inputArray); i++) {
        printCharacter(inputArray[i]);
        for (int offset = 7; offset >= 0; offset--) { // Start from 7 and decrement towards 0
            for (int row = 0; row < 8; row++) {
                byte data = 0;
                for (int col = 0; col < 8; col++) {
                    data |= (matrice[row][(col + offset) % 8] << (7 - col));
                }
                sendCommand(row + 1, data);
            }
            delay(deltaT);
        }
    }
}


  // Scorrimento della matrice

}


// FUNZIONI

void printCharacter(char character) {
    int index = -1;

    if (character >= 'A' && character <= 'Z') {
        index = character - 'A';
    } else if (character >= 'a' && character <= 'z') {
        index = 26 + (character - 'a');
    } else if (character >= '0' && character <= '9') {
        index = 52 + (character - '0');
    } else {
        switch (character) {
            case '!':
                index = 62;
                break;
            case '#':
                index = 63;
                break;
            case '$':
                index = 64;
                break;
            case '%':
                index = 65;
                break;
            case '&':
                index = 66;
                break;
            case '?':
                index = 67;
                break;
        }
    }

    if (index != -1) {
        for (int i = 0; i < 8; i++) {
            uint8_t row = charMatrix[index][i];
            for (int j = 0; j < 8; j++) {
                matrice[i][j] = (row & (1 << (7 - j))) ? 1 : 0;
            }
        }
        bitFlip(); // Specchia la matrice
    }
}

void leggiFrase() {
    String inputString = Serial.readString();
    inputArray[inputString.length() + 1];
    inputString.toCharArray(inputArray, inputString.length() + 1);
    
    fraseInserita = true; // Imposta il flag a true per indicare che la frase è stata inserita
    
    Serial.println("Frase inserita: ");
    Serial.println(inputArray); // Stampa la frase inserita
  }

void sendCommand(byte addr, byte data)
{
  digitalWrite(CS, LOW);

  // Invia il comando a tutti i MAX7219 nella catena
  for (int i = 0; i < numMax7219; i++)
  {
    sendByte(addr);
    sendByte(data);
  }

  digitalWrite(CS, HIGH);
}
void sendByte(byte data)
{
  for (int i = 7; i >= 0; i--)
  {
    digitalWrite(CLK, LOW);
    digitalWrite(DIN, (data >> i) & 1);
    delayMicroseconds(1);
    digitalWrite(CLK, HIGH);
    delayMicroseconds(1);
  }
}

void bitFlip() {
  for (int y = 0; y < 8; y++) {
    for (int z = 0; z < 4; z++) {
      // Scambia i bit nella stessa colonna, considerando la colonna specchiata
      byte temp = matrice[y][z];
      matrice[y][z] = matrice[y][7 - z];
      matrice[y][7 - z] = temp;
    }
  }
}


//VECCHIA VERSIONE - BACKUP ---------------------------------------------------------
/*
//Pin DI USCITA
#define CS 9  //Chip-Select
#define CLK 10  //Clock
#define DIN 11  //Data-Input

//Variabili
int bit[8];
int valore_reg;
byte addr, data;
byte matrice []={(B00111100),
                 (B01100010),
                 (B01100000),
                 (B01111100),
                 (B01100110),
                 (B01100110),
                 (B01100110),
                 (B00111100)};
 
unsigned long int deltaT = 1; //tempo di ritardo CLK

void setup()
{
 
  Serial.begin(9600);
   
  pinMode(CS, OUTPUT);
  pinMode(CLK, OUTPUT);
  pinMode(DIN, OUTPUT);
  digitalWrite(CS, HIGH);
  digitalWrite(CLK, LOW);
  digitalWrite(DIN, LOW);
  
  TxData(0X0C, 0X01, 1); // normal operation
  delay(100);
  Serial.println("NORMAL MODE");
  
  TxData(0X09, 0X00, 1); // NO DECODE
  delay(100);
  Serial.println("NO DECODE");

  TxData(0X0F, 0X01, 1); // Lamp TEST
  delay(1000);
  Serial.println("LAMP"); 
  
  TxData(0X0F, 0X00, 1); // NO Lamp TEST
  delay(100);
  Serial.println("NOLAMP"); 
  
  TxData(0X0B, 0X07, 1); // normal operation
  delay(100);
  Serial.println("SCAN LIMIT 7");
  
  TxData(0X0A, 0X08, 1); // normal operation
  delay(100);
  Serial.println("INTENSITY 8");
  
  TxData(0X0C, 0X01, 1); // normal operation
  delay(100);
  Serial.println("NORMAL MODE");
  
  
}

void loop()
{
  bitFlip();


  for(byte j=1; j<9; j++)
  {

        byte addr= j; //Da dx a sx, partendo da D0 a D7
        byte data = matrice[j-1];
    
        TxData(addr, data, deltaT);
  }

      
    Serial.println("FINE");
    while(1);

}

//--------------------------------------------------------------

//FUNZIONI

void TxData(byte addr, byte data, byte deltaT)
{
    digitalWrite(CS, LOW);//Inizia la trasmissione
    valore_reg = addr;
    valore_reg = valore_reg << 8;
    valore_reg = valore_reg + data;
    for(int i=0; i<16; i++)
      {
          if(bitRead(valore_reg, 15))//Se l'MSB vale 1, stampa 1
          {
           Serial.print('1');
           digitalWrite(DIN, HIGH);
          }
          else//Se l'MSB vale 0, stampa 0
          {
            Serial.print('0');
            digitalWrite(DIN, LOW);
          }

          delay(deltaT);
          digitalWrite(CLK, HIGH);
          delay(deltaT);
          digitalWrite(CLK, LOW);
          valore_reg = valore_reg << 1;
      }
      
      digitalWrite(CS, HIGH);
      Serial.println("DATA");
      digitalWrite(DIN, LOW);
      delay(100);

}

void bitFlip()
{
   for(int y=0; y<8; y++)
  {
    for(int z=0; z<8; z++)
    {
	bit[z]=bitRead(matrice[y],0);
	matrice[y] = matrice[y] >> 1;
    }
   for (int x = 0; x < 8; x++) 
   {
      bitWrite(matrice[y],7-x, bit[x]);
    }
  }
}


//MATRIX CHARACTERS

const uint8_t charMatrix[][8] = {
  {B00110000, B01111000, B11001100, B11001100, B11111100, B11001100, B11001100, B00000000}, // A
  {B11111100, B01100110, B01100110, B01111100, B01100110, B01100110, B11111100, B00000000}, // B
  {B00111100, B01100110, B01000000, B01000000, B01000000, B01100110, B00111100, B00000000}, // C
  {B11111000, B01101100, B01100110, B01100110, B01100110, B01101100, B11111000, B00000000}, // D
  {B11111110, B01100010, B01101000, B01111000, B01101000, B01100010, B11111110, B00000000}, // E
  {B11111110, B01100010, B01101000, B01111000, B01101000, B01100000, B11110000, B00000000}, // F
  {B00111100, B01100110, B11000000, B11000000, B11001110, B01100110, B00111110, B00000000}, // G
  {B11001100, B11001100, B11001100, B11111100, B11001100, B11001100, B11001100, B00000000}, // H
  {B01111000, B00110000, B00110000, B00110000, B00110000, B00110000, B01111000, B00000000}, // I
  {B00011110, B00001100, B00001100, B00001100, B11001100, B11001100, B01111000, B00000000}, // J
  {B11110110, B01100110, B01101100, B01111000, B01101100, B01100110, B11110110, B00000000}, // K
  {B11110000, B01100000, B01100000, B01100000, B01100010, B01100110, B11111110, B00000000}, // L
  {B11000110, B11101110, B11111110, B11111110, B11010110, B11000110, B11000110, B00000000}, // M
  {B11000110, B11100110, B11110110, B11011110, B11001110, B11000110, B11000110, B00000000}, // N
  {B00111000, B01101100, B11000110, B11000110, B11000110, B01101100, B00111000, B00000000}, // O
  {B11111100, B01100110, B01100110, B01111100, B01100000, B01100000, B11110000, B00000000}, // P
  {B01111000, B11001100, B11001100, B11001100, B11011100, B01111000, B00011100, B00000000}, // Q
  {B11111100, B01100110, B01100110, B01111100, B01101100, B01100110, B11110110, B00000000}, // R
  {B01111000, B11001100, B11100000, B01110000, B00011100, B11001100, B01111000, B00000000}, // S
  {B11111100, B10110100, B00110000, B00110000, B00110000, B00110000, B01111000, B00000000}, // T
  {B11001100, B11001100, B11001100, B11001100, B11001100, B11001100, B11111100, B00000000}, // U
  {B11001100, B11001100, B11001100, B11001100, B11001100, B01111000, B00110000, B00000000}, // V
  {B11000110, B11000110, B11000110, B11010110, B11111110, B11101110, B11000110, B00000000}, // W
  {B11000110, B11000110, B01101100, B00111000, B00111000, B01101100, B11000110, B00000000}, // X
  {B11001100, B11001100, B11001100, B01111000, B00110000, B00110000, B01111000, B00000000}, // Y
  {B11111110, B11000110, B10001100, B00011000, B00110010, B01100110, B11111110, B00000000}, // Z
  {B00000000, B00000000, B01111000, B00001100, B01111100, B11001100, B01110110, B00000000}, // a
  {B11100000, B01100000, B01100000, B01111100, B01100110, B01100110, B11011100, B00000000}, // b
  {B00000000, B00000000, B01111000, B11001100, B11000000, B11001100, B01111000, B00000000}, // c
  {B00011100, B00001100, B00001100, B01111100, B11001100, B11001100, B01110110, B00000000}, // d
  {B00000000, B00000000, B01111000, B11001100, B11111100, B11000000, B01111000, B00000000}, // e
  {B00111000, B01101100, B01100000, B11110000, B01100000, B01100000, B11110000, B00000000}, // f
  {B00000000, B00000000, B01110110, B11001100, B11001100, B01111100, B00001100, B11111000}, // g
  {B11100000, B01100000, B01101100, B01110110, B01100110, B01100110, B11100110, B00000000}, // h
  {B00110000, B00000000, B01110000, B00110000, B00110000, B00110000, B01111000, B00000000}, // i
  {B00001100, B00000000, B00001100, B00001100, B00001100, B11001100, B11001100, B01111000}, // j
  {B11100000, B01100000, B01100110, B01101100, B01111000, B01101100, B11100110, B00000000}, // k
  {B01110000, B00110000, B00110000, B00110000, B00110000, B00110000, B01111000, B00000000}, // l
  {B00000000, B00000000, B11001100, B11111110, B11111110, B11010110, B11000110, B00000000}, // m
  {B00000000, B00000000, B11111000, B11001100, B11001100, B11001100, B11001100, B00000000}, // n
  {B00000000, B00000000, B01111000, B11001100, B11001100, B11001100, B01111000, B00000000}, // o
  {B00000000, B00000000, B11011100, B01100110, B01100110, B01111100, B01100000, B11110000}, // p
  {B00000000, B00000000, B01110110, B11001100, B11001100, B01111100, B00001100, B00011110}, // q
  {B00000000, B00000000, B10011100, B01110110, B01100110, B01100000, B11110000, B00000000}, // r
  {B00000000, B00000000, B01111100, B11000000, B01111000, B00001100, B11111000, B00000000}, // s
  {B00010000, B00110000, B01111100, B00110000, B00110000, B00110100, B00011000, B00000000}, // t
  {B00000000, B00000000, B11001100, B11001100, B11001100, B11001100, B01110110, B00000000}, // u
  {B00000000, B00000000, B11001100, B11001100, B11001100, B01111000, B00110000, B00000000}, // v
  {B00000000, B00000000, B11000110, B11000110, B11010110, B11111110, B01101100, B00000000}, // w
  {B00000000, B00000000, B11000110, B01101100, B00111000, B01101100, B11000110, B00000000}, // x
  {B00000000, B00000000, B11001100, B11001100, B11001100, B01111100, B00001100, B11111000}, // y
  {B00000000, B00000000, B11111100, B10011000, B00110000, B01100100, B11111100, B00000000}, // z
  {B01111000, B11001100, B11011100, B11111100, B11101100, B11001100, B01111100, B00000000}, // 0
  {B00110000, B01110000, B00110000, B00110000, B00110000, B00110000, B11111100, B00000000}, // 1
  {B01111000, B11001100, B00001100, B00111000, B01100000, B11001100, B11111100, B00000000}, // 2
  {B01111000, B11001100, B00001100, B00111000, B00001100, B11001100, B01111000, B00000000}, // 3
  {B00011100, B00111100, B01101100, B11001100, B11111110, B00001100, B00011110, B00000000}, // 4
  {B11111100, B11000000, B11111000, B00001100, B00001100, B11001100, B01111000, B00000000}, // 5
  {B00111000, B01100000, B11000000, B11111000, B11001100, B11001100, B01111000, B00000000}, // 6
  {B11111100, B11001100, B00001100, B00011000, B00110000, B00110000, B00110000, B00000000}, // 7
  {B01111000, B11001100, B11001100, B01111000, B11001100, B11001100, B01111000, B00000000}, // 8
  {B01111000, B11001100, B11001100, B01111100, B00001100, B00011000, B01110000, B00000000}, // 9
  {B00110000, B01111000, B01111000, B00110000, B00110000, B00000000, B00110000, B00000000}, // !
  {B01101100, B01101100, B11111110, B01101100, B11111110, B01101100, B01101100, B00000000}, // #
  {B00110000, B01111100, B11000000, B01111000, B00001100, B11111000, B00110000, B00000000}, // $
  {B00000000, B11000110, B11001100, B00011000, B00110000, B01100110, B11000110, B00000000}, // %
  {B00111000, B01101100, B00111000, B01110110, B11011100, B11001100, B01110110, B00000000}, // &
  {B01111000, B11001100, B00001100, B00011000, B00110000, B00000000, B00110000, B00000000}  // ?
  };













  byte lettereMaiuscole[][8] = {
  {B00110000, B01111000, B11001100, B11001100, B11111100, B11001100, B11001100, B00000000}, // A
  {B11111100, B01100110, B01100110, B01111100, B01100110, B01100110, B11111100, B00000000}, // B
  {B00111100, B01100110, B01000000, B01000000, B01000000, B01100110, B00111100, B00000000}, // C
  {B11111000, B01101100, B01100110, B01100110, B01100110, B01101100, B11111000, B00000000}, // D
  {B11111110, B01100010, B01101000, B01111000, B01101000, B01100010, B11111110, B00000000}, // E
  {B11111110, B01100010, B01101000, B01111000, B01101000, B01100000, B11110000, B00000000}, // F
  {B00111100, B01100110, B11000000, B11000000, B11001110, B01100110, B00111110, B00000000}, // G
  {B11001100, B11001100, B11001100, B11111100, B11001100, B11001100, B11001100, B00000000}, // H
  {B01111000, B00110000, B00110000, B00110000, B00110000, B00110000, B01111000, B00000000}, // I
  {B00011110, B00001100, B00001100, B00001100, B11001100, B11001100, B01111000, B00000000}, // J
  {B11110110, B01100110, B01101100, B01111000, B01101100, B01100110, B11110110, B00000000}, // K
  {B11110000, B01100000, B01100000, B01100000, B01100010, B01100110, B11111110, B00000000}, // L
  {B11000110, B11101110, B11111110, B11111110, B11010110, B11000110, B11000110, B00000000}, // M
  {B11000110, B11100110, B11110110, B11011110, B11001110, B11000110, B11000110, B00000000}, // N
  {B00111000, B01101100, B11000110, B11000110, B11000110, B01101100, B00111000, B00000000}, // O
  {B11111100, B01100110, B01100110, B01111100, B01100000, B01100000, B11110000, B00000000}, // P
  {B01111000, B11001100, B11001100, B11001100, B11011100, B01111000, B00011100, B00000000}, // Q
  {B11111100, B01100110, B01100110, B01111100, B01101100, B01100110, B11110110, B00000000}, // R
  {B01111000, B11001100, B11100000, B01110000, B00011100, B11001100, B01111000, B00000000}, // S
  {B11111100, B10110100, B00110000, B00110000, B00110000, B00110000, B01111000, B00000000}, // T
  {B11001100, B11001100, B11001100, B11001100, B11001100, B11001100, B11111100, B00000000}, // U
  {B11001100, B11001100, B11001100, B11001100, B11001100, B01111000, B00110000, B00000000}, // V
  {B11000110, B11000110, B11000110, B11010110, B11111110, B11101110, B11000110, B00000000}, // W
  {B11000110, B11000110, B01101100, B00111000, B00111000, B01101100, B11000110, B00000000}, // X
  {B11001100, B11001100, B11001100, B01111000, B00110000, B00110000, B01111000, B00000000}, // Y
  {B11111110, B11000110, B10001100, B00011000, B00110010, B01100110, B11111110, B00000000}  // Z
};

byte lettereMinuscole[][8] = {
  {B00000000, B00000000, B01111000, B00001100, B01111100, B11001100, B01110110, B00000000}, // a
  {B11100000, B01100000, B01100000, B01111100, B01100110, B01100110, B11011100, B00000000}, // b
  {B00000000, B00000000, B01111000, B11001100, B11000000, B11001100, B01111000, B00000000}, // c
  {B00011100, B00001100, B00001100, B01111100, B11001100, B11001100, B01110110, B00000000}, // d
  {B00000000, B00000000, B01111000, B11001100, B11111100, B11000000, B01111000, B00000000}, // e
  {B00111000, B01101100, B01100000, B11110000, B01100000, B01100000, B11110000, B00000000}, // f
  {B00000000, B00000000, B01110110, B11001100, B11001100, B01111100, B00001100, B11111000}, // g
  {B11100000, B01100000, B01101100, B01110110, B01100110, B01100110, B11100110, B00000000}, // h
  {B00110000, B00000000, B01110000, B00110000, B00110000, B00110000, B01111000, B00000000}, // i
  {B00001100, B00000000, B00001100, B00001100, B00001100, B11001100, B11001100, B01111000}, // j
  {B11100000, B01100000, B01100110, B01101100, B01111000, B01101100, B11100110, B00000000}, // k
  {B01110000, B00110000, B00110000, B00110000, B00110000, B00110000, B01111000, B00000000}, // l
  {B00000000, B00000000, B11001100, B11111110, B11111110, B11010110, B11000110, B00000000}, // m
  {B00000000, B00000000, B11111000, B11001100, B11001100, B11001100, B11001100, B00000000}, // n
  {B00000000, B00000000, B01111000, B11001100, B11001100, B11001100, B01111000, B00000000}, // o
  {B00000000, B00000000, B11011100, B01100110, B01100110, B01111100, B01100000, B11110000}, // p
  {B00000000, B00000000, B01110110, B11001100, B11001100, B01111100, B00001100, B00011110}, // q
  {B00000000, B00000000, B10011100, B01110110, B01100110, B01100000, B11110000, B00000000}, // r
  {B00000000, B00000000, B01111100, B11000000, B01111000, B00001100, B11111000, B00000000}, // s
  {B00010000, B00110000, B01111100, B00110000, B00110000, B00110100, B00011000, B00000000}, // t
  {B00000000, B00000000, B11001100, B11001100, B11001100, B11001100, B01110110, B00000000}, // u
  {B00000000, B00000000, B11001100, B11001100, B11001100, B01111000, B00110000, B00000000}, // v
  {B00000000, B00000000, B11000110, B11000110, B11010110, B11111110, B01101100, B00000000}, // w
  {B00000000, B00000000, B11000110, B01101100, B00111000, B01101100, B11000110, B00000000}, // x
  {B00000000, B00000000, B11001100, B11001100, B11001100, B01111100, B00001100, B11111000}, // y
  {B00000000, B00000000, B11111100, B10011000, B00110000, B01100100, B11111100, B00000000}  // z
};

byte cifre[][8] = {
  {B01111000, B11001100, B11011100, B11111100, B11101100, B11001100, B01111100, B00000000}, // 0
  {B00110000, B01110000, B00110000, B00110000, B00110000, B00110000, B11111100, B00000000}, // 1
  {B01111000, B11001100, B00001100, B00111000, B01100000, B11001100, B11111100, B00000000}, // 2
  {B01111000, B11001100, B00001100, B00111000, B00001100, B11001100, B01111000, B00000000}, // 3
  {B00011100, B00111100, B01101100, B11001100, B11111110, B00001100, B00011110, B00000000}, // 4
  {B11111100, B11000000, B11111000, B00001100, B00001100, B11001100, B01111000, B00000000}, // 5
  {B00111000, B01100000, B11000000, B11111000, B11001100, B11001100, B01111000, B00000000}, // 6
  {B11111100, B11001100, B00001100, B00011000, B00110000, B00110000, B00110000, B00000000}, // 7
  {B01111000, B11001100, B11001100, B01111000, B11001100, B11001100, B01111000, B00000000}, // 8
  {B01111000, B11001100, B11001100, B01111100, B00001100, B00011000, B01110000, B00000000}  // 9
};
*/