1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
char alphabet[] = "abcdefghijklmnopqrstuvwxyz/|}" // '/' means space between letters, '|' means space between words, '}' means end of message
string morse[] {".-","-...","-.-.","-..", ".", "..-.", "--.", "....", "..",
".---", "-.-", ".-..", "--","-.", "---", ".--.", "--.-", ".-.", "...", "-",
"..-", "...-", ".--", "-..-", "-.--", "--.."," "," ",".-.-."};
void main(){
char message[] = ('whatever');
char morse_code[] = message_to_morse(message);
int i = 0;
while (morse_code[i] != NULL){
if(morse_code[i] == '.'){
send_high();
send_low();
}
else if(morse_code[i] == '-'){
send_high();
send_high();
send_high();
send_low();
}
else if(morse[i]_code == ' '){
send_low();
}
i++;
}
}
char message_to_morse[](char c[]){
int i = 0;
char morse_message[];
while(c[i] != NULL){
morse_message[i] = character_to_morse(c[i]);
}
return morse_message;
}
char character_to_morse[](char c){
char found[];
int index = 0;
while(true){
if(alphabet[index] == c){
found = morse[index];
break;
}else{
index++;
}
}
return found;
}
|