Idea is to check a string for a character and not concat it if it is already in the string.
My if statement does not work and I do not have a clue why.
My if statement does not work and I do not have a clue why.
Code:
void random_code() {
// send a random character's Morse equivlent
char* code_char[] =
{ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
",", ".", "?", "!", ":", "\"", "'", "="
};
char* codes[] =
{ ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
"-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", // 26 letters
"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", // 10 numbers
"--..--", ".-.-.-", "..--..", "..--.", "---...", ".-..-.", ".----.", "-...-" // 8 punctuation
};
String send_char; String answers; char* send_codes[row - 1];//array starts at 0. User inputs how many characters in a run (row on screen)
unsigned long seed = seedOut(31); randomSeed(seed);
for (unsigned int t = 0; t < row ; t++) // each run will be 'row' characters (+ 'row' spaces)
{
unsigned int randNumber = random(43); // 0 - 43, all characters.
String chkchr = code_char[randNumber]; // the ascii character random has picked
// PROBLEM IS HERE ---------------------------------------------------------------------------------------------------------
if (chkchr == (answers.substring(0))) // see if the randNumber character is in string 'answers'. I will fix this later if a row is > 44
{
t = t - 1;
}
//----------------------------------------------------------------------------------------------------------------------------
else
{
answers.concat(code_char[randNumber]); answers.concat(" ");
send_codes[t] = (codes[randNumber]); // array of code character strings to be sent
}
}
Serial.println(answers); Serial.println();
}