Arduino CW-trainer

Doel van het project : Leren morse op te nemen en te seinen.

  • Eerst word er een willekeurige calls gegenereerd. Die bestaan uit 3 tot 6 characters.
  • Vervolgens word deze verzonden, op een vooraf ingestelde snelheid.
  • Dan krijgt de leerling de kans de call te seinen.
  • Deze call word gedecodeerd en vergeleken met de verzonden call.
  • Als deze gelijk zijn, krijgt de leerling “groen” licht.
  • Mocht deze niet gelijk zijn, dan krijgt de leerling nog twee kansen.
  • De score wordt bijgehouden en op het display getoond.

Versie 11-03-2019.

Main:

[code]
int led12 = 12; // blink an led on output 12
int led6 = 6; // blink an led on output 6
int audio8 = 8; // output audio on pin 8
int note = 1000; // sound note/pitch
int dotLen = 100; // length of the morse code ‘dot’
int dashLen = dotLen * 3; // length of the morse code ‘dash’
int elemPause = dotLen; // length of the pause between elements of a character
int Spaces = dotLen * 3; // length of the spaces between characters
int wordPause = dotLen * 7; // length of the pause between words
int randNumber;
int prefixNumber;
int numberNumber;
int suffixNumber;
int Char1;
int Char2;
int Char3;
int Char4;
int Char5;
String Charac1;
String Charac2;
String Charac3;
String Charac4;
String Charac5;
String stringMorseCode[6];

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
random_call;
zenden;
}

void loop() {
random_call;
zenden();
}
[/code]

Random_call:

[code]
void random_call() {
prefixNumber = random (1, 3); // 1 of 2 characters in prefix
numberNumber = random (0, 9); // 0 to 9 number
suffixNumber = random (1, 4); // 1, 2 of 3 characters in suffix
Char1 = random (1,27);
Char2 = random (1,27);
Char3 = random (1,27);
Char4 = random (1,27);
Char5 = random (1,27);

switch (Char1) {
case 1:
Charac1 = “A”;
break;
case 2:
Charac1 = “B”;
break;
case 3:
Charac1 = “C”;
break;
case 4:
Charac1 = “D”;
break;
case 5:
Charac1 = “E”;
case 6:
Charac1 = “F”;
break;
case 7:
Charac1 = “G”;
break;
case 8:
Charac1 = “H”;
break;
case 9:
Charac1 = “I”;
break;
case 10:
Charac1 = “J”;
break;
case 11:
Charac1 = “K”;
break;
case 12:
Charac1 = “L”;
break;
case 13:
Charac1 = “M”;
break;
case 14:
Charac1 = “N”;
break;
case 15:
Charac1 = “O”;
break;
case 16:
Charac1 = “P”;
break;
case 17:
Charac1 = “Q”;
break;
case 18:
Charac1 = “R”;
break;
case 19:
Charac1 = “S”;
break;
case 20:
Charac1 = “T”;
break;
case 21:
Charac1 = “U”;
break;
case 22:
Charac1 = “V”;
break;
case 23:
Charac1 = “W”;
break;
case 24:
Charac1 = “X”;
break;
case 25:
Charac1 = “Y”;
break;
case 26:
Charac1 = “Z”;
break;
}
switch (Char2) {
case 1:
Charac2 = “A”;
break;
case 2:
Charac2 = “B”;
break;
case 3:
Charac2 = “C”;
break;
case 4:
Charac2 = “D”;
break;
case 5:
Charac2 = “E”;
case 6:
Charac2 = “F”;
break;
case 7:
Charac2 = “G”;
break;
case 8:
Charac2 = “H”;
break;
case 9:
Charac2 = “I”;
break;
case 10:
Charac2 = “J”;
break;
case 11:
Charac2 = “K”;
break;
case 12:
Charac2 = “L”;
break;
case 13:
Charac2 = “M”;
break;
case 14:
Charac2 = “N”;
break;
case 15:
Charac2 = “O”;
break;
case 16:
Charac2 = “P”;
break;
case 17:
Charac2 = “Q”;
break;
case 18:
Charac2 = “R”;
break;
case 19:
Charac2 = “S”;
break;
case 20:
Charac2 = “T”;
break;
case 21:
Charac2 = “U”;
break;
case 22:
Charac2 = “V”;
break;
case 23:
Charac2 = “W”;
break;
case 24:
Charac2 = “X”;
break;
case 25:
Charac2 = “Y”;
break;
case 26:
Charac2 = “Z”;
break;
}
switch (Char3) {
case 1:
Charac3 = “A”;
break;
case 2:
Charac3 = “B”;
break;
case 3:
Charac3 = “C”;
break;
case 4:
Charac3 = “D”;
break;
case 5:
Charac3 = “E”;
case 6:
Charac3 = “F”;
break;
case 7:
Charac3 = “G”;
break;
case 8:
Charac3 = “H”;
break;
case 9:
Charac3 = “I”;
break;
case 10:
Charac3 = “J”;
break;
case 11:
Charac3 = “K”;
break;
case 12:
Charac3 = “L”;
break;
case 13:
Charac3 = “M”;
break;
case 14:
Charac3 = “N”;
break;
case 15:
Charac3 = “O”;
break;
case 16:
Charac3 = “P”;
break;
case 17:
Charac3 = “Q”;
break;
case 18:
Charac3 = “R”;
break;
case 19:
Charac3 = “S”;
break;
case 20:
Charac3 = “T”;
break;
case 21:
Charac3 = “U”;
break;
case 22:
Charac3 = “V”;
break;
case 23:
Charac3 = “W”;
break;
case 24:
Charac3 = “X”;
break;
case 25:
Charac3 = “Y”;
break;
case 26:
Charac3 = “Z”;
break;
}
switch (Char4) {
case 1:
Charac4 = “A”;
break;
case 2:
Charac4 = “B”;
break;
case 3:
Charac4= “C”;
break;
case 4:
Charac4= “D”;
break;
case 5:
Charac4 = “E”;
case 6:
Charac4 = “F”;
break;
case 7:
Charac4 = “G”;
break;
case 8:
Charac4 = “H”;
break;
case 9:
Charac4 = “I”;
break;
case 10:
Charac4 = “J”;
break;
case 11:
Charac4 = “K”;
break;
case 12:
Charac4 = “L”;
break;
case 13:
Charac4 = “M”;
break;
case 14:
Charac4 = “N”;
break;
case 15:
Charac4 = “O”;
break;
case 16:
Charac4 = “P”;
break;
case 17:
Charac4 = “Q”;
break;
case 18:
Charac4 = “R”;
break;
case 19:
Charac4 = “S”;
break;
case 20:
Charac4 = “T”;
break;
case 21:
Charac4 = “U”;
break;
case 22:
Charac4 = “V”;
break;
case 23:
Charac4 = “W”;
break;
case 24:
Charac4 = “X”;
break;
case 25:
Charac4 = “Y”;
break;
case 26:
Charac4 = “Z”;
break;
}

switch (Char5) {
case 1:
Charac5 = “A”;
break;
case 2:
Charac5 = “B”;
break;
case 3:
Charac5= “C”;
break;
case 4:
Charac5= “D”;
break;
case 5:
Charac5 = “E”;
case 6:
Charac5 = “F”;
break;
case 7:
Charac5 = “G”;
break;
case 8:
Charac5 = “H”;
break;
case 9:
Charac5 = “I”;
break;
case 10:
Charac5 = “J”;
break;
case 11:
Charac5 = “K”;
break;
case 12:
Charac5 = “L”;
break;
case 13:
Charac5 = “M”;
break;
case 14:
Charac5 = “N”;
break;
case 15:
Charac5 = “O”;
break;
case 16:
Charac5 = “P”;
break;
case 17:
Charac5 = “Q”;
break;
case 18:
Charac5 = “R”;
break;
case 19:
Charac5 = “S”;
break;
case 20:
Charac5 = “T”;
break;
case 21:
Charac5 = “U”;
break;
case 22:
Charac5 = “V”;
break;
case 23:
Charac5 = “W”;
break;
case 24:
Charac5 = “X”;
break;
case 25:
Charac5 = “Y”;
break;
case 26:
Charac5 = “Z”;
break;
}
if ( prefixNumber == 1 & suffixNumber == 1 ){
stringMorseCode[1] = Charac1;
stringMorseCode[2] = numberNumber;
stringMorseCode[3] = Charac2;
Serial.print(stringMorseCode[1]);
Serial.print(stringMorseCode[2]);
Serial.print(stringMorseCode[3]);
Serial.println();
zenden;
}
if ( prefixNumber == 1 & suffixNumber == 2 ){
stringMorseCode[1] = Charac1;
stringMorseCode[2] = numberNumber;
stringMorseCode[3] = Charac2;
stringMorseCode[4] = Charac3;
Serial.print(stringMorseCode[1]);
Serial.print(stringMorseCode[2]);
Serial.print(stringMorseCode[3]);
Serial.print(stringMorseCode[4]);
Serial.println();
zenden;
}
if ( prefixNumber == 1 & suffixNumber == 3 ){
stringMorseCode[1] = Charac1;
stringMorseCode[2] = numberNumber;
stringMorseCode[3] = Charac2;
stringMorseCode[4] = Charac3;
stringMorseCode[5] = Charac4;
Serial.print(stringMorseCode[1]);
Serial.print(stringMorseCode[2]);
Serial.print(stringMorseCode[3]);
Serial.print(stringMorseCode[4]);
Serial.print(stringMorseCode[5]);
Serial.println();
}
if ( prefixNumber == 2 & suffixNumber == 1 ){
stringMorseCode[1] = Charac1;
stringMorseCode[2] = Charac2;
stringMorseCode[3] = numberNumber;
stringMorseCode[4] = Charac3;
Serial.print(stringMorseCode[1]);
Serial.print(stringMorseCode[2]);
Serial.print(stringMorseCode[3]);
Serial.print(stringMorseCode[4]);
Serial.println();
}
if ( prefixNumber == 2 & suffixNumber == 2 ){
stringMorseCode[1] = Charac1;
stringMorseCode[2] = Charac2;
stringMorseCode[3] = numberNumber;
stringMorseCode[4] = Charac3;
stringMorseCode[5] = Charac4;
Serial.print(stringMorseCode[1]);
Serial.print(stringMorseCode[2]);
Serial.print(stringMorseCode[3]);
Serial.print(stringMorseCode[4]);
Serial.print(stringMorseCode[5]);
Serial.println();
}
if ( prefixNumber == 2 & suffixNumber == 3 ){
stringMorseCode[1] = Charac1;
stringMorseCode[2] = Charac2;
stringMorseCode[3] = numberNumber;
stringMorseCode[4] = Charac3;
stringMorseCode[5] = Charac4;
stringMorseCode[6] = Charac5;
Serial.print(stringMorseCode[1]);
Serial.print(stringMorseCode[2]);
Serial.print(stringMorseCode[3]);
Serial.print(stringMorseCode[4]);
Serial.print(stringMorseCode[5]);
Serial.print(stringMorseCode[6]);
Serial.println();
}
}
[/code]

Zenden:

w.a.g.