I need do a morse translator, but it doesn't do anything and I don't know why, can someone help me?
I'm not a professional in the coding, but I know some things.
struct Caracts{
String a = ".-";
String b = "-...";
String c = "-.-.";
String d = "-..";
String e = ".";
String f = "..-.";
String g = "--.";
String h = "....";
String i = "..";
String j = ".---";
String k = "-.-";
String l = ".-..";
String m = "--";
String n = "-.";
String o = "---";
String p = ".--.";
String q = "--.-";
String r = ".-.";
String s = "...";
String t = "-";
String u = "..-";
String v = "...-";
String w = ".--";
String x = "-..-";
String y = "-.--";
String z = "--..";
};
Caracts mor;
int i = 0;
int l = 0;
String matriz[] = {};
String letras = "";
String punto = ".";
String guion = "-";
String espacio = " ";
int tiempo_guion = 2.5;
int tiempo_term = 1;
int tiempo_espacio = 5;
int tiempo_activo = 0;
int tiempo_inactivo = 0;
void setup() {
pinMode(2, OUTPUT);//led
pinMode(5, OUTPUT);//buzzer
pinMode(8, OUTPUT);//boton
Serial.begin(9600);
}
void carga(String mat[], int i); //esta matriz carga caracteres dentro de la matriz principal
void mostrar(String mat[], String letras, int l);
void cantidadMatriz(String mat[], int l);//esta matriz cuenta la cantidad de caracteres que tiene la matriz principal
void loop() {
carga(matriz, i);
}
void carga(String mat[], int i){
int j = 0;
while(j < 1){
if( digitalRead(8) == 0){
digitalWrite(2, LOW);
digitalWrite(5, LOW);
while(digitalRead(8) == 0){
tiempo_inactivo += 1;
}
if(tiempo_inactivo == tiempo_term){
mostrar(mat, letras, l);
j++;
}
if(tiempo_inactivo > tiempo_espacio and tiempo_inactivo < tiempo_term){
mat[i] = espacio;
i++;
}
if(tiempo_inactivo < tiempo_term and tiempo_inactivo >= 7500){
while(tiempo_inactivo < tiempo_term){
digitalWrite(2, HIGH);
delay(50);
digitalWrite(2, LOW);
}
}
}
if( digitalRead(8)== 1){
while(digitalRead(8) == 1){
tiempo_activo += 1;
}
digitalWrite(2, HIGH);
digitalWrite(5, HIGH);
delay(tiempo_activo);
digitalWrite(2, LOW);
digitalWrite(5, LOW);
if(tiempo_activo < tiempo_guion){
mat[i] = punto;
i++;
}
if(tiempo_activo >= tiempo_guion and tiempo_activo < tiempo_espacio){
digitalWrite(2, HIGH);
digitalWrite(5, HIGH);
delay(tiempo_activo);
digitalWrite(2, LOW);
digitalWrite(5, LOW);
mat[i] = guion;
i++;
}
}
}
cantidadMatriz(matriz, l);
}
void cantidadMatriz(String mat[], int l){
int i = 0;
if(mat[i] == punto or mat[i] == guion or mat[i] == espacio){
l++;
i++;
}
}
void mostrar(String mat[], String letras, int l){
for(int j = 0; j < l; j++){
if(mat[j] != espacio){
Serial.print(mat[j]);
letras = mat[j];
}
else{
if(letras == mor.a){
Serial.print("\t");
Serial.print('a');
}
if(letras == mor.b){
Serial.print("\t");
Serial.print('b');
}
if(letras == mor.c){
Serial.print("\t");
Serial.print('c');
}
if(letras == mor.d){
Serial.print("\t");
Serial.print('d');
}
if(letras == mor.e){
Serial.print("\t");
Serial.print('e');
}
if(letras == mor.f){
Serial.print("\t");
Serial.print('f');
}
if(letras == mor.g){
Serial.print("\t");
Serial.print('g');
}
if(letras == mor.h){
Serial.print("\t");
Serial.print('h');
}
if(letras == mor.i){
Serial.print("\t");
Serial.print('i');
}
if(letras == mor.j){
Serial.print("\t");
Serial.print('j');
}
if(letras == mor.k){
Serial.print("\t");
Serial.print('k');
}
if(letras == mor.l){
Serial.print("\t");
Serial.print('l');
}
if(letras == mor.m){
Serial.print("\t");
Serial.print('m');
}
if(letras == mor.n){
Serial.print("\t");
Serial.print('n');
}
if(letras == mor.o){
Serial.print("\t");
Serial.print('o');
}
if(letras == mor.p){
Serial.print("\t");
Serial.print('p');
}
if(letras == mor.q){
Serial.print("\t");
Serial.print('q');
}
if(letras == mor.r){
Serial.print("\t");
Serial.print('r');
}
if(letras == mor.s){
Serial.print("\t");
Serial.print('s');
}
if(letras == mor.t){
Serial.print("\t");
Serial.print('t');
}
if(letras == mor.u){
Serial.print("\t");
Serial.print('u');
}
if(letras == mor.v){
Serial.print("\t");
Serial.print('v');
}
if(letras == mor.w){
Serial.print("\t");
Serial.print('w');
}
if(letras == mor.x){
Serial.print("\t");
Serial.print('x');
}
if(letras == mor.y){
Serial.print("\t");
Serial.print('y');
}
if(letras == mor.z){
Serial.print("\t");
Serial.print('z');
}
Serial.println(mat[j]);
}
}
}