int t = 150; // one unit of time in milliseconds void setup() { pinMode(13, OUTPUT); } void dot() { digitalWrite(13, HIGH); delay(1*t); digitalWrite(13, LOW); delay(1*t); } void dash() { digitalWrite(13, HIGH); delay(3*t); digitalWrite(13, LOW); delay(1*t); } void letter() { delay(2*t); // plus one unit from end of dot/dash = 3 units } void word() { delay(6*t); // plus one unit from end of dot/dash = 7 units } void sendMorsePattern(char *pattern) { int i = 0; while (0 != pattern[i]) { int c = pattern[i]; if ('.' == c) dot(); else if ('-' == c) dash(); i = i+1; } letter(); } void sendMorse(char *message) { int i = 0; while (0 != message[i]) { // convert character at index i into the corresponding pattern switch (message[i]) { case 'a': case 'A': sendMorsePattern(".-" ); break; case 'b': case 'B': sendMorsePattern("-..." ); break; case 'c': case 'C': sendMorsePattern("-.-." ); break; case 'd': case 'D': sendMorsePattern("-.." ); break; case 'e': case 'E': sendMorsePattern("." ); break; case 'f': case 'F': sendMorsePattern("..-." ); break; case 'g': case 'G': sendMorsePattern("--." ); break; case 'h': case 'H': sendMorsePattern("...." ); break; case 'i': case 'I': sendMorsePattern(".." ); break; case 'j': case 'J': sendMorsePattern(".---" ); break; case 'k': case 'K': sendMorsePattern("-.-" ); break; case 'l': case 'L': sendMorsePattern(".-.." ); break; case 'm': case 'M': sendMorsePattern("--" ); break; case 'n': case 'N': sendMorsePattern("-." ); break; case 'o': case 'O': sendMorsePattern("---" ); break; case 'p': case 'P': sendMorsePattern(".--." ); break; case 'q': case 'Q': sendMorsePattern("--.-" ); break; case 'r': case 'R': sendMorsePattern(".-." ); break; case 's': case 'S': sendMorsePattern("..." ); break; case 't': case 'T': sendMorsePattern("-" ); break; case 'u': case 'U': sendMorsePattern("..-" ); break; case 'v': case 'V': sendMorsePattern("...-" ); break; case 'w': case 'W': sendMorsePattern(".--" ); break; case 'x': case 'X': sendMorsePattern("-..-" ); break; case 'y': case 'Y': sendMorsePattern("-.--" ); break; case 'z': case 'Z': sendMorsePattern("--.." ); break; case '1': sendMorsePattern(".----" ); break; case '2': sendMorsePattern("..---" ); break; case '3': sendMorsePattern("...--" ); break; case '4': sendMorsePattern("....-" ); break; case '5': sendMorsePattern("....." ); break; case '6': sendMorsePattern("-...." ); break; case '7': sendMorsePattern("--..." ); break; case '8': sendMorsePattern("---.." ); break; case '9': sendMorsePattern("----." ); break; case '0': sendMorsePattern("-----" ); break; case ',': sendMorsePattern("--..--"); break; case '.': sendMorsePattern(".-.-.-"); break; case '?': sendMorsePattern("..--.."); break; case ';': sendMorsePattern("-.-.-."); break; case ':': sendMorsePattern("---..."); break; case '/': sendMorsePattern("-..-. "); break; case '-': sendMorsePattern("-....-"); break; case '\'': sendMorsePattern(".----."); break; case '"': sendMorsePattern(".-..-."); break; case '(': sendMorsePattern("-.--." ); break; case ')': sendMorsePattern("-.--.-"); break; case '=': sendMorsePattern("-...-" ); break; case '+': sendMorsePattern(".-.-." ); break; case '*': sendMorsePattern("-..-" ); break; case '@': sendMorsePattern(".--.-."); break; default: word(); } i = i + 1; } } void loop() { sendMorse("introduction to design track 2"); // enough SOS already delay(8*t); }