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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<title>Morse Code Decoder</title>
|
| 5 |
+
<style>
|
| 6 |
+
body {
|
| 7 |
+
font-family: sans-serif;
|
| 8 |
+
display: flex;
|
| 9 |
+
flex-direction: column;
|
| 10 |
+
align-items: center;
|
| 11 |
+
padding: 20px;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
.container {
|
| 15 |
+
width: 80%;
|
| 16 |
+
max-width: 600px;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
textarea, input {
|
| 20 |
+
width: 100%;
|
| 21 |
+
padding: 8px;
|
| 22 |
+
margin-bottom: 10px;
|
| 23 |
+
box-sizing: border-box;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
button {
|
| 27 |
+
padding: 10px 20px;
|
| 28 |
+
background-color: #4CAF50;
|
| 29 |
+
color: white;
|
| 30 |
+
border: none;
|
| 31 |
+
cursor: pointer;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
button:hover {
|
| 35 |
+
background-color: #3e8e41;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
#led {
|
| 39 |
+
width: 50px;
|
| 40 |
+
height: 50px;
|
| 41 |
+
border-radius: 50%;
|
| 42 |
+
background-color: gray;
|
| 43 |
+
margin-top: 10px;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
.alphabet-container {
|
| 47 |
+
display: flex;
|
| 48 |
+
flex-wrap: wrap;
|
| 49 |
+
justify-content: center;
|
| 50 |
+
margin-top: 20px;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.alphabet-letter {
|
| 54 |
+
width: 30px;
|
| 55 |
+
height: 30px;
|
| 56 |
+
display: flex;
|
| 57 |
+
align-items: center;
|
| 58 |
+
justify-content: center;
|
| 59 |
+
border: 1px solid #ccc;
|
| 60 |
+
margin: 5px;
|
| 61 |
+
cursor: pointer;
|
| 62 |
+
user-select: none; /* Prevent text selection on click */
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
.alphabet-letter:hover {
|
| 66 |
+
background-color: #f0f0f0;
|
| 67 |
+
}
|
| 68 |
+
#status {
|
| 69 |
+
margin-top: 10px;
|
| 70 |
+
font-style: italic;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
</style>
|
| 74 |
+
</head>
|
| 75 |
+
<body>
|
| 76 |
+
|
| 77 |
+
<div class="container">
|
| 78 |
+
<h1>Morse Code Decoder</h1>
|
| 79 |
+
|
| 80 |
+
<label for="morseInput">Morse Code Input:</label>
|
| 81 |
+
<textarea id="morseInput" rows="4"></textarea>
|
| 82 |
+
|
| 83 |
+
<button onclick="decodeMorse()">Decode</button>
|
| 84 |
+
|
| 85 |
+
<label for="decodedText">Decoded Text:</label>
|
| 86 |
+
<textarea id="decodedText" rows="4" readonly></textarea>
|
| 87 |
+
|
| 88 |
+
<h2>LED Output</h2>
|
| 89 |
+
<div id="led"></div>
|
| 90 |
+
|
| 91 |
+
<h2>Alphabet Input</h2>
|
| 92 |
+
<div class="alphabet-container" id="alphabetContainer">
|
| 93 |
+
</div>
|
| 94 |
+
|
| 95 |
+
<p id="status">Ready</p>
|
| 96 |
+
</div>
|
| 97 |
+
|
| 98 |
+
<script>
|
| 99 |
+
const MORSE_CODE_DICT = {
|
| 100 |
+
'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.',
|
| 101 |
+
'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..',
|
| 102 |
+
'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.',
|
| 103 |
+
'S': '...', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-',
|
| 104 |
+
'Y': '-.--', 'Z': '--..', '1': '.----', '2': '..---', '3': '...--',
|
| 105 |
+
'4': '....-', '5': '.....', '6': '-....', '7': '--...', '8': '---..',
|
| 106 |
+
'9': '----.', '0': '-----', ', ': '--..--', '.': '.-.-.-', '?': '..--..',
|
| 107 |
+
'/': '-..-.', '-': '-....-', '(': '-.--.', ')': '-.--.-'
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
const dotDuration = 200; // milliseconds
|
| 111 |
+
const dashDuration = dotDuration * 3;
|
| 112 |
+
const spaceDuration = dotDuration * 7;
|
| 113 |
+
const letterSpaceDuration = dotDuration * 3;
|
| 114 |
+
|
| 115 |
+
const morseInput = document.getElementById("morseInput");
|
| 116 |
+
const decodedText = document.getElementById("decodedText");
|
| 117 |
+
const led = document.getElementById("led");
|
| 118 |
+
const alphabetContainer = document.getElementById("alphabetContainer");
|
| 119 |
+
const status = document.getElementById("status");
|
| 120 |
+
|
| 121 |
+
// Generate alphabet buttons
|
| 122 |
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
| 123 |
+
for (let i = 0; i < alphabet.length; i++) {
|
| 124 |
+
const letter = alphabet[i];
|
| 125 |
+
const letterDiv = document.createElement("div");
|
| 126 |
+
letterDiv.classList.add("alphabet-letter");
|
| 127 |
+
letterDiv.textContent = letter;
|
| 128 |
+
letterDiv.addEventListener("click", function() {
|
| 129 |
+
if (MORSE_CODE_DICT[letter]) {
|
| 130 |
+
morseInput.value += MORSE_CODE_DICT[letter] + " "; // Add space after each letter
|
| 131 |
+
} else {
|
| 132 |
+
alert("Morse Code not found for this Character")
|
| 133 |
+
}
|
| 134 |
+
});
|
| 135 |
+
alphabetContainer.appendChild(letterDiv);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
function decodeMorse() {
|
| 139 |
+
const morseCode = morseInput.value.toUpperCase().trim();
|
| 140 |
+
status.textContent = "Decoding..."; // Start decoding
|
| 141 |
+
|
| 142 |
+
if (!morseCode) {
|
| 143 |
+
status.textContent = "Please enter Morse code.";
|
| 144 |
+
return;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
try {
|
| 148 |
+
const decoded = morseToText(morseCode);
|
| 149 |
+
decodedText.value = decoded;
|
| 150 |
+
status.textContent = "Decoding Complete" // Success!
|
| 151 |
+
displayLED(morseCode);
|
| 152 |
+
} catch (error) {
|
| 153 |
+
decodedText.value = error; // Display Error
|
| 154 |
+
status.textContent = `Error: ${error}`;
|
| 155 |
+
turnOffLED(); // Turn off led
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
function morseToText(morseCode) {
|
| 161 |
+
morseCode = morseCode.replace("/", " / "); // Handle word separators
|
| 162 |
+
const words = morseCode.split(" / ");
|
| 163 |
+
let text = "";
|
| 164 |
+
for (const word of words) {
|
| 165 |
+
const letters = word.split(" ");
|
| 166 |
+
for (const letter of letters) {
|
| 167 |
+
let found = false;
|
| 168 |
+
for (const key in MORSE_CODE_DICT) {
|
| 169 |
+
if (MORSE_CODE_DICT[key] === letter) {
|
| 170 |
+
text += key;
|
| 171 |
+
found = true;
|
| 172 |
+
break;
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
if (!found && letter) {
|
| 176 |
+
throw `Invalid Morse code: ${letter}`; // Throw exception for non found letters
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
+
text += " ";
|
| 180 |
+
}
|
| 181 |
+
return text.trim();
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
function displayLED(morseCode) {
|
| 185 |
+
let i = 0;
|
| 186 |
+
function animate() {
|
| 187 |
+
if (i < morseCode.length) {
|
| 188 |
+
const symbol = morseCode[i];
|
| 189 |
+
if (symbol === '.') {
|
| 190 |
+
turnOnLED();
|
| 191 |
+
setTimeout(() => {
|
| 192 |
+
turnOffLED();
|
| 193 |
+
setTimeout(() => {
|
| 194 |
+
i++;
|
| 195 |
+
animate();
|
| 196 |
+
}, dotDuration);
|
| 197 |
+
}, dotDuration);
|
| 198 |
+
} else if (symbol === '-') {
|
| 199 |
+
turnOnLED();
|
| 200 |
+
setTimeout(() => {
|
| 201 |
+
turnOffLED();
|
| 202 |
+
setTimeout(() => {
|
| 203 |
+
i++;
|
| 204 |
+
animate();
|
| 205 |
+
}, dotDuration);
|
| 206 |
+
}, dashDuration);
|
| 207 |
+
} else if (symbol === ' ') {
|
| 208 |
+
setTimeout(() => {
|
| 209 |
+
i++;
|
| 210 |
+
animate();
|
| 211 |
+
}, letterSpaceDuration);
|
| 212 |
+
}
|
| 213 |
+
else if (symbol === '/') {
|
| 214 |
+
setTimeout(() => {
|
| 215 |
+
i++;
|
| 216 |
+
animate();
|
| 217 |
+
}, spaceDuration);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
} else {
|
| 221 |
+
turnOffLED();
|
| 222 |
+
}
|
| 223 |
+
}
|
| 224 |
+
animate();
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
function turnOnLED() {
|
| 228 |
+
led.style.backgroundColor = "yellow";
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
function turnOffLED() {
|
| 232 |
+
led.style.backgroundColor = "gray";
|
| 233 |
+
}
|
| 234 |
+
</script>
|
| 235 |
+
|
| 236 |
+
</body>
|
| 237 |
+
</html>
|