LPC1768 programm for the led matrix.

Dependencies:   BufferedSerial DS3231 mbed-rtos mbed

Revision:
3:bd1352d4dbb8
Parent:
2:d5472e4a55bf
--- a/setMatrix.cpp	Wed Oct 12 13:22:19 2016 +0000
+++ b/setMatrix.cpp	Wed Jan 17 07:12:35 2018 +0000
@@ -1,544 +1,937 @@
-#include "initalize.h"
-#include "alphabet.h"
-#include "mbed.h"
-#include <string>
+#include "initalize.h"  //Funktionenprototypen
+#include "alphabet.h"   //Header mit allen Buchstaben und Zeichen Variationen
+#include "mbed.h"       //
+#include <string>       //
+#include "rtos.h"       //Verwendet für RtosTimer
+#include <BufferedSerial.h> //MCU besitzt eine Buffer-Limite von 16 bytes. Diese Library erweitert diese Limite
+#include "DS3231.h"     //Library für die Echtzeituhr DS3231
+#include "project.h"    //Definitionen
+#include "time_adjustment_dates.h"  //Daten für die Winter und Sommerzeit
+
+//============================================================================================
+//VARIABLEN
+
 
-/*
- __   __        _      _    _        
- \ \ / /_ _ _ _(_)__ _| |__| |___ ___
-  \ V / _` | '_| / _` | '_ \ / -_|_-<
-   \_/\__,_|_| |_\__,_|_.__/_\___/__/
+struct LED_Matrix
+{
+    DigitalOut ds,oe,stcp,shcp,mr;
+    LED_Matrix(PinName pin1, PinName pin2, PinName pin3, PinName pin4, PinName pin5) : ds(pin1), oe(pin2), stcp(pin3), shcp(pin4), mr(pin5) {};    
+};
+//PIN-ASSIGNMENT------------------------------------------------------------------------------
+DS3231      RTC(p28,p27);   //RTC über p28(SDA) und p27(SCL) verbunden
+
+BusOut      led(LED1,LED2,LED3,LED4);   
+
+LED_Matrix  matrix(p5, p6, p7, p8, p9); //LED-Matrix Data, Enable, Storage, Shift, Masterreset
+
+RtosTimer   customDuration(CustomTextCycleFinished);    //Timer für benutzerdefinierter Text
+RtosTimer   TimerTextSwitch(textSwitcher);              //Timer für den Wechsel zwischen Zeit und Datum
+
+BufferedSerial bluetooth(p13,p14); //Bluetooth Modul, tx, rx
 
-*/
-
-int m_speed, m_loop;
+//GLOBAL VARIABLE----------------------------------------------------------------------------------
+//Clock
+int     rtc_hour;       //Stunden
+int     rtc_minute;     //Minuten
+int     rtc_second;     //Sekunden
+int     rtc_date;       //Datum
+int     rtc_dayOfWeek;  //Tag der Woche
+int     rtc_month;      //Monat
+int     rtc_year;       //Jahr
+//
+//Time Values
+int     CustomDuration = TIME_CUSTOM_DEF;
 
-int c_frame,                // frame-counter
-    speed,                  // Variable for setting up, how fast the matrix would scroll
-    ble,                    // Variable as "getting text from Bluetooth"-signal
-    frames;                 // Variable for the scrolling of the text
-string text_bluetooth (""); // will be empty, is going to be used for the bluetooth module
-//------------------------------------------------------------------------------------------------------
+//bluetooth
+string  TextBluetooth ("");
+char    ErrorValue = 0;
+
+//matrix
+bool    matrix_setScroll = 1;
+char    textSwitch = matrixTIME;
+string  TextMatrix    ("");
+
+int     matrixPos = 0;
+int     matrix_frames;              // Bilder-Counter
+int     matrix_moveFrame = 0;       // Variable zum Verschieben des Textes
+
+
+//ENUM & STRUCT-------------------------------------------------------------------------------
+
+//============================================================================================
 
-DigitalOut  ds1(p5), oe1(p6), stcp1(p7), shcp1(p8), mr1(p9), led(LED1);
-AnalogIn    ain(p20);
-Ticker      tick;
-Serial pc(USBTX, USBRX); // tx, rx
-/*
-DS    normal        Serial Data Output  Schreibt vor ob das LED 0 oder 1 ist.
-OE    invertiert    Output-Enable       Aktiviert oder deaktiviert die LEDs.
-SHCP  normal        Shift register clk  Setzt Position mit kurzen Impulsen fest.
-STCP  normal        Storage reg. clk    Setzt Reihe mit kurzen Impulsen fest.
-MR    invertiert    Master reset        resetet den Storage. Muss mit STCP angezeigt werden.
-*/
-//------------------------------------------------------------------------------------------------------
-/*
-  ___             _   _             
- | __|  _ _ _  __| |_(_)___ _ _  ___
- | _| || | ' \/ _|  _| / _ \ ' \(_-<
- |_| \_,_|_||_\__|\__|_\___/_||_/__/
-                                    
-*/
-
-void Matrix(int m_length, int m_height, int *matrix_text,const string text_generic)
+//============================================================================================
+//▄     ▄  ▄▄▄  ▄▄▄▄▄ ▄▄▄▄  ▄▄▄ ▄   ▄
+//█▀▄ ▄▀█ █   █   █   █   █  █  █   █
+//█  ▀  █ █▄▄▄█   █   █▄▄▄▀  █   ▀▄▀
+//█     █ █   █   █   █ ▀▄   █  ▄▀ ▀▄
+//█     █ █   █   █   █  ▀▄ ▄█▄ █   █
+//MATRIX=======================================================================
+//Autor:        Joel von Rotz
+//Typ:          void
+//parameter:    int m_length,   int m_height,   char *matrix_value
+//              Matrixlänge     Matrixhöhe      Array für Textwerte
+//Beschreibung: 
+//=============================================================================
+void Matrix(int m_length, int m_height, char *matrix_value)
 {
-    init();
+    matrix.oe = 1;                //Matrix ausschalten, damit keine unerwünschte LEDs leuchten.
+    TextMatrix = TextStandard;  //Standard-Text zuweisen
     wait(0.5);
-    reset_srg();
-    wait(0.05);
-    setText(text_generic,matrix_text);
-    wait(0.05);
-    setMatrix(m_height, m_length, matrix_text);
+    matrix.oe = 0;                //Matrix wieder einschalten
+    
+    RTC.setI2Cfrequency(400000);
+    bluetooth.baud(115200); //Bluetooth Module Communication
+    
+    TimerTextSwitch.start(TIME_CHANGE);
+    
+    while(1)
+    {
+        initVal();          //Variabeln initialisieren
+        
+        for(int x = 0; x < 512; x++)   //matrix_value "leeren"
+            matrix_value[x] = 0x00;
+        
+        
+        ReadTimeToString();    //Lese Zeit und konvertiere zu einem String
+        
+        
+        TextMatrixConvert(TextMatrix,matrix_value, m_length);
+        
+        /*Überprüft ob es sich um Winterzeit oder Sommerzeit handelt*/
+        WinterSummerTime(rtc_year,rtc_month,rtc_date,rtc_hour,rtc_second);
+        //----------------------------//
+        if((matrix_frames-64) > m_length)
+        {   
+            matrix_setScroll = 1;   
+        }
+        else
+        {   
+            matrix_setScroll = 0;   
+        }
+        if(!matrix_setScroll)
+        {   
+            matrix_moveFrame = 64;  
+        }
+        //----------------------------//
+        setMatrix(m_height, m_length, matrix_value);
+        //----------------------------//
+        if(bluetooth.readable())
+        {
+            bluetooth_matrix(m_length,m_height,matrix_value);
+        }
+        //----------------------------//
+    }
 }
 
-void init()
+//TEXTSWITCHER=================================================================
+//Autor:        Joel von Rotz
+//Typ:          void
+//parameter:    void
+//Beschreibung: Wird für das Wechseln des Textes benötigt
+//=============================================================================
+void textSwitcher(void)
+{
+    matrixPos = 0;
+    matrix_moveFrame = 0;
+    textSwitch = !textSwitch;
+}
+
+void CustomTextCycleFinished(void)
+{
+    TimerTextSwitch.start(TIME_CHANGE);
+    customDuration.stop();
+    textSwitch = matrixTIME;
+    TextMatrix = TextStandard;
+    
+}
+
+//INITVAL======================================================================
+//Autor:        Joel von Rotz
+//Typ:          void
+//parameter:    void
+//Beschreibung: Initialisierung der Variabeln und Ein-Ausgängen
+//=============================================================================
+void initVal(void)
 {
-    mr1 = 1;
-    oe1 = 0;
-    ds1 = 0;
-    stcp1 = 0;
-    shcp1 = 0;
-    frames = 0;
-    c_frame = 0;
-    m_loop = 1;
+    //Überprüfung, ob Text verschoben werden muss auf dem Display
+    
+    //=====================
+    //Output
+    matrix.mr = 1;
+    matrix.oe = 1;
+    matrix.ds = 0;
+    matrix.stcp = 0;
+    matrix.shcp = 0;
+    //=====================
+    //Variabeln
+    matrix_frames = 0;
+    TextBluetooth = "";
+    reset_srg();
+}
+
+//MATRIX=======================================================================
+//Autor:        Joel von Rotz
+//Typ:          void
+//parameter:    int m_height, int m_length, char *matrix_value
+//Beschreibung: Lässt Text oder anderes auf einer LED-Matrix anzeigen
+//=============================================================================
+//  MATRIX
+//Lässt einen Text auf dem Display anzeigen
+void setMatrix(int m_height,int m_length, char *matrix_value)
+{  
+    //clock wird als Zählvariable verwendet, darunter als Bitshifter und Multiplexer
+    for(int frequency = 0; frequency < 4; frequency++)
+    {
+        for(int clock = 0; clock < 8; clock++)
+        {
+            //Der Text muss von hinten nach vorne abgearbeitet werden, darum wird eine Variable
+            //names matrixPos verwendet, die die Position des Textes bestimmt.
+            if(matrixPos <= 0)
+                matrixPos = m_length;   //setze matrixPos auf die letzte Position des Textes zurück
+                
+    
+            for(int fill = 0; fill < (m_length/8); fill++)
+            {
+                for(int column = 8; column > 0; column--)
+                {
+                    matrix.ds = (matrix_value[matrixPos-column+matrix_moveFrame] >> clock) & 1;
+                    shift_srg();
+                }
+                matrixPos -= 8;
+            }
+            //Multiplexer
+            //mit dieser For-Schleife wird der Multiplex-Bit gesetzt
+            for(int cell = 0; cell < 8; cell++)
+            {
+                if(clock == cell)   //ist clock gleich cell?
+                    matrix.ds = 1;      //setze Data-Pin auf 1
+                else                //Sonst
+                    matrix.ds = 0;      //setze auf 0
+                shift_srg();        //Schiebe Data in die Register hinein
+            }
+            
+            store_srg();
+            matrix.oe = 0;
+            wait_us(1000);
+            matrix.oe = 1;
+        }
+        
+    }
+    //===================================================================
+    if(matrix_setScroll) 
+    {
+        matrix_moveFrame++;
+    }
+    if(matrix_moveFrame >= matrix_frames)
+    {
+        matrix_moveFrame = 0; 
+    }
+    //===================================================================
 }
 
 
+//Schieberegister mit einem Bit befüllen
 void shift_srg()
 {
-    wait_ms(0.05);     // Perioden-Dauer 2ms, später verkürzen
-    shcp1 = 1;
-    wait_ms(0.05);
-    shcp1 = 0;
+    matrix.shcp = 1;   
+    matrix.shcp = 0;
 }
 
+//Speicher von den Schieberegister herausgeben
+void store_srg()
+{
+    matrix.stcp = 1;
+    matrix.stcp = 0;
+}
+
+//Schieberegister zurücksetzen
 void reset_srg()
 {
-    mr1 = 0;
-    wait_ms(0.05);     // Reset-Puls 1ms, später verkürzen
-    mr1 = 1;   
+    matrix.mr = 0;
+    matrix.mr = 1;   
 }
 
-
-void setSpeed()
+/*Steuerung für die LED-Matrix*/
+void bluetooth_matrix(int m_length, int m_height, char *matrix_value)
 {
-    // not possible with simple if-loops
-    if(ain > 0.125f)  
-        m_speed = 10;
-    if(ain > 0.25f)   
-        m_speed = 25;
-    if(ain > 0.375f)  
-        m_speed = 50;
-    if(ain > 0.5f)    
-        m_speed = 100;
-    if(ain > 0.625f)  
-        m_speed = 250;
-    if(ain > 0.75f)   
-        m_speed = 500;
-    if(ain > 0.875f)  
-        m_speed = 1000;
-    if(ain > 0.97f)   
-        m_speed = 2000;
+    TextBluetooth = "";            
+    ErrorValue = NO_ERROR;
+    string buff;
+    
+    while(bluetooth.readable())
+    {
+        TextBluetooth += bluetooth.getc();   
+    }
+    //------------------------------------------
+    //Bluetooth Nachrichten
+    if(TextBluetooth.size()==28 && TextBluetooth.find("matrixCONNECT") != string::npos)
+    {
+        TextMatrix = "Connected!";    
+        bluetooth.printf("Hallo! Schreibe etwas...");
+    }
+    else if(TextBluetooth.size()==17 && TextBluetooth.find("matrixNEW_PAIRING") != string::npos ||
+            TextBluetooth.size()==16 && TextBluetooth.find("matrixDISCONNECT") != string::npos  )
+    {
+        TextBluetooth = "";
+    }
+    //------------------------------------------
+    //Zeit einstellen
+    else if(TextBluetooth.at(0) == '?') //ist das erste Zeichen ein Befehlszeichen
+    {   
+        TextBluetooth.erase(0,1);
+        /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
+        if(TextBluetooth.find("ST ")== 0)   //Konfiguration Zeit
+        {   TextBluetooth.erase(0,3);
+            if(TextBluetooth.size() == 8)
+            {
+                
+                buff.assign(TextBluetooth,0,2);
+                rtc_hour = atoi(buff.c_str());
+                buff.assign(TextBluetooth,3,2);
+                rtc_minute = atoi(buff.c_str());
+                buff.assign(TextBluetooth,6,2);
+                rtc_second = atoi(buff.c_str());
+                if(rtc_hour <= 23 && rtc_minute <= 59 && rtc_second <= 59)
+                {
+                    RTC.setTime(rtc_hour,rtc_minute,rtc_second);
+                }
+                else
+                {   
+                    ErrorValue = CMD_NOT_IN_RANGE;
+                }
+            }
+            else
+            {   
+                ErrorValue = CMD_NOT_COMPLETE;
+            }
+        }
+        /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
+        else if(TextBluetooth.find("SD ")== 0)  //Konfiguration Datum
+        {   TextBluetooth.erase(0,3);
+            if(TextBluetooth.size() == 10)
+            {
+                /*Konvertiere String zu Int*/
+                buff.assign(TextBluetooth,0,2);
+                rtc_date = atoi(buff.c_str());
+                buff.assign(TextBluetooth,3,2);
+                rtc_month = atoi(buff.c_str());
+                buff.assign(TextBluetooth,6,4);
+                rtc_year = atoi(buff.c_str());
+                if(rtc_year <= 2100 && rtc_year >= 1900 && checkDate(rtc_year,rtc_month,rtc_date))
+                {
+                    RTC.setDate(0,rtc_date,rtc_month,rtc_year);
+                }
+                else if( ErrorValue == FEB_NO_LEAP) {}
+                else
+                {   
+                    ErrorValue = CMD_NOT_IN_RANGE;
+                }
+            }
+            else
+            {   
+                ErrorValue = CMD_NOT_COMPLETE;   
+            }
+        }
+        /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
+        else if(TextBluetooth.find("SW ")== 0)  //Konfiguration Winterzeit
+        {   TextBluetooth.erase(0,3);
+            TextBluetooth = "Winterzeit";
+        }
+        /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
+        else if(TextBluetooth.find("SS ")== 0)  //Konfiguration Sommerzeit
+        {   TextBluetooth.erase(0,3);
+            TextBluetooth = "Sommerzeit";
+        }
+        /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
+        else if(TextBluetooth.find("CD ")== 0)  //Konfiguration Benutzerdefinierte Textdauer
+        {   TextBluetooth.erase(0,3);
+            if(TextBluetooth.size() == 3)
+            {
+                CustomDuration = atoi(TextBluetooth.c_str());
+                if(CustomDuration <= 600 && CustomDuration >= 1){}
+                else
+                {
+                    ErrorValue = CMD_NOT_IN_RANGE;
+                    CustomDuration = TIME_CUSTOM_DEF;
+                }
+            }
+            else
+            {   
+                ErrorValue = CMD_NOT_COMPLETE;   
+            }
+        }
+        /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
+        else
+        {
+            ErrorValue = INVALID_CMD;
+        }
+        BLE_ErrorHandler(ErrorValue);
+    }
+    //-----------------------------------------------------
+    //Benutzerdefinierter Text
+    else
+    {
+        TextMatrix = TextBluetooth;
+        textSwitch = matrixCUSTOM;
+        TimerTextSwitch.stop();         //Stoppe den Timer für den Zeit-Datum-Wechsel
+        customDuration.start(CustomDuration*1000);   //2 Minuten eigener Text
+    }
 }
 
+void BLE_ErrorHandler(char value)
+{
+    switch(value)
+    {
+    case NO_ERROR:
+        TimerTextSwitch.start(TIME_CHANGE);
+        customDuration.stop();
+        textSwitch = matrixTIME;
+        break;
+    case INVALID_CMD:
+        TextMatrix = "ERROR: Invalid Command";
+        break;
+    case CMD_NOT_COMPLETE:
+        TextMatrix = "ERROR: Missing Command Parameters";
+        break;
+    case CMD_NOT_IN_RANGE:
+        TextMatrix = "ERROR: Values Not In Range";
+        break;
+    case FEB_NO_LEAP:
+        TextMatrix = "ERROR: February-Date Too Big (Not a Leapyear)";
+        break;
+    }
+    if(value != NO_ERROR)
+    {
+        textSwitch = matrixCUSTOM;
+        TimerTextSwitch.stop();         //Stoppe den Timer für den Zeit-Datum-Wechsel
+        customDuration.start(10000);   //2 Minuten eigener Text
+    }
+}
+
+void WinterSummerTime(int yearVal,int monthVal,int dateVal,int hourVal,int secondVal)
+{
+    /*timeLock wird als Wiederholungsstop verwendet. Da bei der Winterzeit eine Stunden *
+     *zurückgestellt wird, wird die Zeit immer wieder um eine Stunde zurückgestellt.    */
+    static bool timeLock = 0;
+    
+    //Summertime
+    if( dateVal  == summerdates[(yearVal % 2000)][0] &&
+        monthVal == summerdates[(yearVal % 2000)][1] &&
+        (yearVal % 2000)== summerdates[(yearVal % 2000)][2] &&
+        hourVal  == summerdates[(yearVal % 2000)][3] &&
+        secondVal== summerdates[(yearVal % 2000)][4] &&
+        timeLock == 1)
+    {
+        timeLock = 0;
+        hourVal += 1;
+        RTC.setTime(hourVal,rtc_minute,rtc_second);
+    }
+    //WINTERTIME
+    if( dateVal  == winterdates[(yearVal % 2000)][0] &&
+        monthVal == winterdates[(yearVal % 2000)][1] &&
+        (yearVal % 2000)== winterdates[(yearVal % 2000)][2] &&
+        hourVal  == winterdates[(yearVal % 2000)][3] &&
+        secondVal== winterdates[(yearVal % 2000)][4] &&
+        timeLock == 0)
+    {
+        timeLock = 1;
+        hourVal -= 1;
+        RTC.setTime(hourVal,rtc_minute,rtc_second);
+    }
+}
+
+//=============================================================================
+
 
-void setMatrix(int m_height,int m_length, int *matrix_text)
+//TimeStringConvert============================================================
+//Autor:        Joel von Rotz
+//Typ:          void
+//parameter:    void
+//Beschreibung: 
+//      Das Datum und die Uhrzeit wird am Terminal angezeigt.
+//=============================================================================
+void ReadTimeToString(void)
 {
-    //bool row_temp[m_height];           // temporary array for matrix output
-       
-    while(1)
+    RTC.readDateTime(&rtc_dayOfWeek,&rtc_date,&rtc_month,&rtc_year,&rtc_hour,&rtc_minute,&rtc_second);
+    char buff[100];
+    if(textSwitch == matrixTIME)
+    {
+        sprintf(buff,"   %02i:%02i:%02i",rtc_hour,rtc_minute,rtc_second);
+        
+    }
+    else if(textSwitch == matrixDATE)
+    {    
+        sprintf(buff,"  %02i.%02i.%04i",rtc_date,rtc_month,rtc_year);
+    }
+    if(textSwitch != matrixCUSTOM)
     {
-        for(int frequency = 0; frequency < 50; frequency++)
-        {
-            for(int position = 0; position < m_length; position++)
-            {
-                for(int column = 0; column < m_length; column++)
-                {
-                    if(column == position)
-                    {
-                        ds1 = 1;
-                    }
-                    else
-                    {
-                        ds1 = 0;
-                    }
-                    shift_srg();
-                }
-                
-                for(int shift_int = 0; shift_int < m_height; shift_int++)
-                {
-                    ds1 = (matrix_text[position] >> shift_int) & 1;
-                    shift_srg();
-                }
-                stcp1 = 1;
-                wait_ms(0.5);
-                stcp1 = 0;
-            }
-        }
-        frames++;
-        if(frames == c_frame)
-            frames = 0;
-     }
+        TextMatrix = buff;
+    }
 }
+//=============================================================================
+
+//SETDATEMAX===================================================================
+//Autor:        Joel von Rotz
+//Typ:          char
+//parameter:    int monthVal (Monat wird übergeben)
+//Beschreibung: 
+//      Es wird anhand dem Monat die dazugehörigen maximalen Tagen zurück-
+//      gegeben.
+//=============================================================================
+bool checkDate(int yearVal, int monthVal, int dateVal)
+{
+    const char month_limit[12]={31,28,31,30,31,30,31,31,30,31,30,31};
+    if(monthVal == februar && checkLeapyear(yearVal))
+    {   return true;    }
+    else if(dateVal > 28 && monthVal == februar)
+    {   
+        ErrorValue = FEB_NO_LEAP;
+        return false;   
+    }
+    if(dateVal <= month_limit[monthVal-1] && dateVal >= 1)
+    {   return true;    }
+    else
+    {   return false;   }
+}
+//=============================================================================
 
 
-void initArray(int const *letter, int size, int *matrix_text)
+//CHECKLEAPYEAR================================================================
+//Autor:        Joel von Rotz
+//Typ:          bool
+//parameter:    int yearVal
+//Beschreibung: 
+//  Es wird überprüft, ob das Jahr ein Schaltjahr ist oder nicht.
+//  Dabei ist das Jahr NUR ein Schaltjahr, wenn das Jahr durch 4 oder durch 400 
+//  teilbar, aber sobald es durch 100 teilbar ist, ist es kein Schaltjahr.
+//  Source -> Gregorianischer Kalender 
+//=============================================================================
+#define ISLEAPYEAR    1
+#define ISNOTLEAPYEAR 0
+bool checkLeapyear(int yearVal)
 {
-    c_frame = c_frame + 1;  // A small space, about 1 led column, is being added.
+    if(yearVal % 4 == 0)
+    {
+        if(yearVal % 100 == 0)
+        {
+            if(yearVal % 400 == 0)
+            {
+                return ISLEAPYEAR;   //ist Schaltjahr
+            }
+            return ISNOTLEAPYEAR;   //ist nicht Schaltjahr
+        }
+        return ISLEAPYEAR;   //ist Schaltjahr
+    }
+    return ISNOTLEAPYEAR;   //ist nicht Schaltjahr
+}
+//=============================================================================
+
+void initArray(int const *letter, int size, char *matrix_value)
+{
+    matrix_frames = matrix_frames + 1;  /*A small space, about 1 led column, is being added.        */
     
     for(int position = 0; position < size; position++)
     {
-        matrix_text[c_frame] = letter[position];
-        c_frame++;
+        /*  Hex-values are added to the matrix-text and matrix_frames is incremented          */
+        matrix_value[matrix_frames] = letter[position];
+        matrix_frames++;
     }
-    matrix_text[c_frame] = 0x00;           
+    matrix_value[matrix_frames] = 0x00;           
 }
 
-void setText(const string& text_dummy, int *matrix_text)      
-// Used to identifiy which letter is in the set String-Position.                                  
-// If it contains a specific letter, it will call another Function called "initArray" to fill up the array which is then used to show the letters on the Matrix
+//=============================================================================//
+//=============================================================================//
+void TextMatrixConvert(const string& text_convertion, char *matrix_value, int m_length)      
 {
-    for(int LetterPos = 0; LetterPos < text_dummy.size(); LetterPos++)
+    matrix_frames = matrix_frames + 64;
+    for(int LetterPos = 0; LetterPos < text_convertion.size(); LetterPos++)
     {
         //Letters ------------------------
-        if     (text_dummy.at(LetterPos) == 'A')
+        if     (text_convertion.at(LetterPos) == 'A')
         {   
-            initArray(A,4,matrix_text);   
+            initArray(A,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'a')
+        else if(text_convertion.at(LetterPos) == 'a')
         {   
-            initArray(a,4,matrix_text);   
+            initArray(a,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'B')
+        else if(text_convertion.at(LetterPos) == 'B')
         {   
-            initArray(B,4,matrix_text);   
+            initArray(B,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'b')
+        else if(text_convertion.at(LetterPos) == 'b')
         {   
-            initArray(b,5,matrix_text);   
+            initArray(b,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'C')
+        else if(text_convertion.at(LetterPos) == 'C')
         {   
-            initArray(C,4,matrix_text);   
+            initArray(C,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'c')
+        else if(text_convertion.at(LetterPos) == 'c')
         {   
-            initArray(c,4,matrix_text);   
+            initArray(c,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'D')
+        else if(text_convertion.at(LetterPos) == 'D')
         {   
-            initArray(D,4,matrix_text);   
+            initArray(D,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'd')
+        else if(text_convertion.at(LetterPos) == 'd')
         {   
-            initArray(d,5,matrix_text);   
+            initArray(d,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'E')
+        else if(text_convertion.at(LetterPos) == 'E')
         {   
-            initArray(E,4,matrix_text);   
+            initArray(E,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'e')
+        else if(text_convertion.at(LetterPos) == 'e')
         {   
-            initArray(e,4,matrix_text);   
+            initArray(e,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'F')
+        else if(text_convertion.at(LetterPos) == 'F')
         {   
-            initArray(F,4,matrix_text);   
+            initArray(F,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'f')
+        else if(text_convertion.at(LetterPos) == 'f')
         {   
-            initArray(f,3,matrix_text);   
+            initArray(f,3,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'G')
+        else if(text_convertion.at(LetterPos) == 'G')
         {   
-            initArray(G,4,matrix_text);   
+            initArray(G,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'g')
+        else if(text_convertion.at(LetterPos) == 'g')
         {   
-            initArray(g,4,matrix_text);   
+            initArray(g,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'H')
+        else if(text_convertion.at(LetterPos) == 'H')
         {   
-            initArray(H,4,matrix_text);   
+            initArray(H,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'h')
+        else if(text_convertion.at(LetterPos) == 'h')
         {   
-            initArray(h,5,matrix_text);   
+            initArray(h,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'I')
+        else if(text_convertion.at(LetterPos) == 'I')
         {   
-            initArray(I,3,matrix_text);   
+            initArray(I,3,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'i')
+        else if(text_convertion.at(LetterPos) == 'i')
         {   
-            initArray(i,3,matrix_text);   
+            initArray(i,3,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'J')
+        else if(text_convertion.at(LetterPos) == 'J')
         {   
-            initArray(J,4,matrix_text);   
+            initArray(J,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'j')
+        else if(text_convertion.at(LetterPos) == 'j')
         {   
-            initArray(j,3,matrix_text);   
+            initArray(j,3,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'K')
+        else if(text_convertion.at(LetterPos) == 'K')
         {   
-            initArray(K,5,matrix_text);   
+            initArray(K,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'k')
+        else if(text_convertion.at(LetterPos) == 'k')
         {   
-            initArray(k,4,matrix_text);   
+            initArray(k,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'L')
+        else if(text_convertion.at(LetterPos) == 'L')
         {   
-            initArray(L,4,matrix_text);   
+            initArray(L,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'l')
+        else if(text_convertion.at(LetterPos) == 'l')
         {   
-            initArray(l,3,matrix_text);   
+            initArray(l,3,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'M')
+        else if(text_convertion.at(LetterPos) == 'M')
         {   
-            initArray(M,5,matrix_text);   
+            initArray(M,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'm')
+        else if(text_convertion.at(LetterPos) == 'm')
         {   
-            initArray(m,5,matrix_text);   
+            initArray(m,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'N')
+        else if(text_convertion.at(LetterPos) == 'N')
         {   
-            initArray(N,5,matrix_text);   
+            initArray(N,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'n')
+        else if(text_convertion.at(LetterPos) == 'n')
         {   
-            initArray(n,4,matrix_text);   
+            initArray(n,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'O')
+        else if(text_convertion.at(LetterPos) == 'O')
         {   
-            initArray(O,4,matrix_text);   
+            initArray(O,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'o')
+        else if(text_convertion.at(LetterPos) == 'o')
         {   
-            initArray(o,5,matrix_text);   
+            initArray(o,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'P')
+        else if(text_convertion.at(LetterPos) == 'P')
         {   
-            initArray(P,4,matrix_text);   
+            initArray(P,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'p')
+        else if(text_convertion.at(LetterPos) == 'p')
         {   
-            initArray(p,4,matrix_text);   
+            initArray(p,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'Q')
+        else if(text_convertion.at(LetterPos) == 'Q')
         {   
-            initArray(Q,5,matrix_text);   
+            initArray(Q,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'q')
+        else if(text_convertion.at(LetterPos) == 'q')
         {   
-            initArray(q,4,matrix_text);   
+            initArray(q,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'R')
+        else if(text_convertion.at(LetterPos) == 'R')
         {   
-            initArray(R,4,matrix_text);   
+            initArray(R,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'r')
+        else if(text_convertion.at(LetterPos) == 'r')
         {   
-            initArray(r,3,matrix_text);   
+            initArray(r,3,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'S')
+        else if(text_convertion.at(LetterPos) == 'S')
         {   
-            initArray(S,4,matrix_text);   
+            initArray(S,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 's')
+        else if(text_convertion.at(LetterPos) == 's')
         {   
-            initArray(s,4,matrix_text);   
+            initArray(s,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'T')
+        else if(text_convertion.at(LetterPos) == 'T')
         {   
-            initArray(T,5,matrix_text);   
+            initArray(T,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 't')
+        else if(text_convertion.at(LetterPos) == 't')
         {   
-            initArray(t,3,matrix_text);   
+            initArray(t,3,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'U')
+        else if(text_convertion.at(LetterPos) == 'U')
         {   
-            initArray(U,4,matrix_text);   
+            initArray(U,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'u')
+        else if(text_convertion.at(LetterPos) == 'u')
         {   
-            initArray(u,5,matrix_text);   
+            initArray(u,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'V')
+        else if(text_convertion.at(LetterPos) == 'V')
         {   
-            initArray(V,5,matrix_text);   
+            initArray(V,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'v')
+        else if(text_convertion.at(LetterPos) == 'v')
         {   
-            initArray(v,5,matrix_text);   
+            initArray(v,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'W')
+        else if(text_convertion.at(LetterPos) == 'W')
         {   
-            initArray(W,5,matrix_text);   
+            initArray(W,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'w')
+        else if(text_convertion.at(LetterPos) == 'w')
         {   
-            initArray(w,5,matrix_text);   
+            initArray(w,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'X')
+        else if(text_convertion.at(LetterPos) == 'X')
         {   
-            initArray(X,4,matrix_text);   
+            initArray(X,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'x')
+        else if(text_convertion.at(LetterPos) == 'x')
         {   
-            initArray(x,4,matrix_text);   
+            initArray(x,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'Y')
+        else if(text_convertion.at(LetterPos) == 'Y')
         {   
-            initArray(Y,5,matrix_text);   
+            initArray(Y,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'y')
+        else if(text_convertion.at(LetterPos) == 'y')
         {   
-            initArray(y,5,matrix_text);   
+            initArray(y,5,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'Z')
+        else if(text_convertion.at(LetterPos) == 'Z')
         {   
-            initArray(Z,4,matrix_text);   
+            initArray(Z,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == 'z')
+        else if(text_convertion.at(LetterPos) == 'z')
         {   
-            initArray(z,4,matrix_text);   
+            initArray(z,4,matrix_value);   
         }
         // Numbers -----------------------
-        else if(text_dummy.at(LetterPos) == '0')
+        else if(text_convertion.at(LetterPos) == '0')
         {   
-            initArray(zero,4,matrix_text);   
+            initArray(zero,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == '1')
+        else if(text_convertion.at(LetterPos) == '1')
         {   
-            initArray(one,3,matrix_text);   
+            initArray(one,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == '2')
+        else if(text_convertion.at(LetterPos) == '2')
         {   
-            initArray(two,4,matrix_text);   
+            initArray(two,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == '3')
+        else if(text_convertion.at(LetterPos) == '3')
         {   
-            initArray(three,4,matrix_text);   
+            initArray(three,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == '4')
+        else if(text_convertion.at(LetterPos) == '4')
         {   
-            initArray(four,4,matrix_text);   
+            initArray(four,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == '5')
+        else if(text_convertion.at(LetterPos) == '5')
         {   
-            initArray(five,4,matrix_text);   
+            initArray(five,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == '6')
+        else if(text_convertion.at(LetterPos) == '6')
         {   
-            initArray(six,4,matrix_text);   
+            initArray(six,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == '7')
+        else if(text_convertion.at(LetterPos) == '7')
         {   
-            initArray(seven,4,matrix_text);   
+            initArray(seven,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == '8')
+        else if(text_convertion.at(LetterPos) == '8')
         {   
-            initArray(eight,4,matrix_text);   
+            initArray(eight,4,matrix_value);   
         }
-        else if(text_dummy.at(LetterPos) == '9')
+        else if(text_convertion.at(LetterPos) == '9')
         {   
-            initArray(nine,4,matrix_text);
+            initArray(nine,4,matrix_value);
         }
         // Symbols -----------------------
-        else if(text_dummy.at(LetterPos) == '!')
+        else if(text_convertion.at(LetterPos) == '!')
         {   
-            initArray(exclam,1,matrix_text);
+            initArray(exclam,1,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '?')
+        else if(text_convertion.at(LetterPos) == '?')
         {   
-            initArray(quest,3,matrix_text);
+            initArray(quest,3,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) ==  34)
+        else if(text_convertion.at(LetterPos) ==  34)
         {  
-            initArray(quote,3,matrix_text);
+            initArray(quote,3,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '#')
+        else if(text_convertion.at(LetterPos) == '#')
         {   
-            initArray(hash,5,matrix_text);
+            initArray(hash,5,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '$')
+        else if(text_convertion.at(LetterPos) == '$')
         {   
-            initArray(dollar,5,matrix_text);
+            initArray(dollar,5,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '%')
+        else if(text_convertion.at(LetterPos) == '%')
         {   
-            initArray(prcent,7,matrix_text);
+            initArray(prcent,7,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '&')
+        else if(text_convertion.at(LetterPos) == '&')
         {   
-            initArray(_and,5,matrix_text);
+            initArray(_and,5,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '(')
+        else if(text_convertion.at(LetterPos) == '(')
         {   
-            initArray(round_o,2,matrix_text);
+            initArray(round_o,2,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == ')')
+        else if(text_convertion.at(LetterPos) == ')')
         {   
-            initArray(round_c,2,matrix_text);
+            initArray(round_c,2,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '*')
+        else if(text_convertion.at(LetterPos) == '*')
         {   
-            initArray(star,5,matrix_text);
+            initArray(star,5,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '+')
+        else if(text_convertion.at(LetterPos) == '+')
         {   
-            initArray(plus,5,matrix_text);
+            initArray(plus,5,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '-')
+        else if(text_convertion.at(LetterPos) == '-')
         {   
-            initArray(minus,3,matrix_text);
+            initArray(minus,3,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '=')
+        else if(text_convertion.at(LetterPos) == '=')
         {   
-            initArray(_equal,3,matrix_text);
+            initArray(_equal,4,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == ',')
+        else if(text_convertion.at(LetterPos) == ',')
         {   
-            initArray(comma,2,matrix_text);
+            initArray(comma,2,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '.')
+        else if(text_convertion.at(LetterPos) == '.')
         {   
-            initArray(point,1,matrix_text);
+            initArray(point,1,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '/')
+        else if(text_convertion.at(LetterPos) == '/')
         {   
-            initArray(slash,5,matrix_text);
+            initArray(slash,5,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) ==  58)
+        else if(text_convertion.at(LetterPos) ==  58)
         {   
-            initArray(d_point,1,matrix_text);
+            initArray(d_point,1,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) ==  59)
+        else if(text_convertion.at(LetterPos) ==  59)
         {   
-            initArray(poicom,2,matrix_text);
+            initArray(poicom,2,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) ==  95)
+        else if(text_convertion.at(LetterPos) ==  95)
         {   
-            initArray(undlin,4,matrix_text);
+            initArray(undlin,4,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) ==  92)
+        else if(text_convertion.at(LetterPos) ==  92)
         {   
-            initArray(b_slash,5,matrix_text);
+            initArray(b_slash,5,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) ==  64)
+        else if(text_convertion.at(LetterPos) ==  64)
         {   
-            initArray(at,5,matrix_text);
+            initArray(at,5,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) ==  62)
+        else if(text_convertion.at(LetterPos) ==  62)
         {   
-            initArray(more,4,matrix_text);
+            initArray(more,4,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) ==  60)
+        else if(text_convertion.at(LetterPos) ==  60)
         {   
-            initArray(less,1,matrix_text);
+            initArray(less,4,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '[')
+        else if(text_convertion.at(LetterPos) == '[')
         {   
-            initArray(brack_o,2,matrix_text);
+            initArray(brack_o,2,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == ']')
+        else if(text_convertion.at(LetterPos) == ']')
         {   
-            initArray(brack_c,2,matrix_text);
+            initArray(brack_c,2,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) ==  94)
+        else if(text_convertion.at(LetterPos) ==  94)
         {   
-            initArray(roof,3,matrix_text);
+            initArray(roof,3,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '{')
+        else if(text_convertion.at(LetterPos) == '{')
         {   
-            initArray(brace_o,3,matrix_text);
+            initArray(brace_o,3,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '}')
+        else if(text_convertion.at(LetterPos) == '}')
         {   
-            initArray(brace_c,3,matrix_text);
+            initArray(brace_c,3,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '~')
+        else if(text_convertion.at(LetterPos) == '~')
         {   
-            initArray(wave,4,matrix_text);
+            initArray(wave,4,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '|')
+        else if(text_convertion.at(LetterPos) == '|')
         {   
-            initArray(stick,1,matrix_text);
+            initArray(stick,1,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == '`')
+        else if(text_convertion.at(LetterPos) == '`')
         {   
-            initArray(frapo,2,matrix_text);
+            initArray(frapo,2,matrix_value);
         }
-        else if(text_dummy.at(LetterPos) == ' ')
+        else if(text_convertion.at(LetterPos) == ' ')
         {   
-            initArray(space,3,matrix_text);
+            initArray(space,3,matrix_value);
         }
     }
-    c_frame += 3;
-}
\ No newline at end of file
+}
+
+//============================================================================================
+//▄▄▄   ▄▄   ▄▄   ▄▄   ▄▄   ▄
+//█  █ █  ▀ ▀  █ ▀  █ ▀  █ ▀█
+//█  █ ▀▄▄   ▄▄▀  ▄▄▀  ▄▄▀  █
+//█  █    █    █ █       █  █
+//█▄▄▀ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ ▄█▄
\ No newline at end of file