-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMorseCodeTransmitter.ino
More file actions
91 lines (76 loc) · 2.35 KB
/
MorseCodeTransmitter.ino
File metadata and controls
91 lines (76 loc) · 2.35 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//The pin numbers' variable
int laserPin = 9;
int ledPin = 10;
int buzzerPin = 11;
//The time durations of signals' outputs
int dotDuration = 800;
int dashDuration = 2000;
int symbolSpace = 250;
int letterSpace = 500;
int wordSpace = 3000;
//The string array to store the morse code translations of the characters
char* morseTable[36] = {
".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---",
"-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-",
"..-", "...-", ".--", "-..-", "-.--", "--..", "-----", ".----", "..---",
"...--", "....-", ".....", "-....", "--...", "---..", "----."
};
//Setting up the pins for output and the serial monitor for input
void setup(){
//Setting the pin modes for output
pinMode(laserPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
//Taking input from the user through the serial monitor
Serial.begin(9600);
Serial.println("Enter a sentence: ");
}
//The loop function for transmission
void loop(){
//Checking if the serial is operational
if(Serial.available()){
String input = Serial.readStringUntil('\n');
input.trim();
//Converting the letters to upper case
input.toUpperCase();
for(int i = 0; i < input.length(); i++){
char c = input[i];
if(c == ' ') {
delay(wordSpace);
}
else if(isAlphaNumeric(c)){
int index;
//Checking if the inputed character is a digit
if(isDigit(c)){
index = c - '0' + 26;
}
else{
index = c - 'A';
}
char* morse = morseTable[index];
//Transmitting the morse code signal
for(int j = 0; j < strlen(morse); j++){
if(morse[j] == '.'){
digitalWrite(laserPin, HIGH);
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
delay(dotDuration);
}
else if(morse[j] == '-'){
digitalWrite(laserPin, HIGH);
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
delay(dashDuration);
}
digitalWrite(laserPin, LOW);
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
delay(symbolSpace);
}
//Delay for letter spaces
delay(letterSpace);
}
}
Serial.println("\nCompleted the transmission.\n");
}
}