int t = 150; // one unit of time in milliseconds void setup() { // put your setup code here, to run once: 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]) { switch (message[i]) { case 'o': case 'O': sendMorsePattern("---"); break; case 's': case 'S': sendMorsePattern("..."); break; default: word(); } i = i + 1; } } void loop() { // put your main code here, to run repeatedly: sendMorse("sos"); }