SOS-Morse-Blink.ino 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. Blink
  3. The basic element of Morse code is the dot and all other elements can be defined in terms of multiples of the dot length.
  4. The word PARIS is used because this is the length of a typical word in English plain text, it has a total length of 50 dot lengths.
  5. If the word PARIS can be sent ten times in a minute using normal Morse code timing then the code speed is 10 WPM.
  6. The character speed is related to dot length in seconds by the following formula:
  7. Speed (WPM) = 2.4 * (Dots per second)
  8. Here are the ratios for the other code elements:
  9. Dot = basic length
  10. Dash length = Dot length x 3
  11. Pause between elements = Dot length
  12. Pause between characters = Dot length x 3
  13. Pause between words (see note) = Dot length x 7
  14. Note: For learning the code this ratio is often increased so that overall text speed is lower than in standard Morse code. This stretched code is called Farnsworth code.
  15. @see http://www.nu-ware.com/NuCode%20Help/index.html?morse_code_structure_and_timing_.htm
  16. @see https://en.wikipedia.org/wiki/Morse_code
  17. */
  18. const unsigned short PIN_OUT = 13;
  19. const unsigned short dotLen = 200;
  20. const unsigned short dashLen = dotLen*3;
  21. const unsigned short elementPause = dotLen;
  22. const unsigned short characterPause = dotLen*3;
  23. const unsigned short wordPause = dotLen*7;
  24. void setup()
  25. {
  26. pinMode(PIN_OUT, OUTPUT);
  27. }
  28. void pause(unsigned short length)
  29. {
  30. digitalWrite(PIN_OUT, LOW);
  31. delay(length);
  32. }
  33. void blink(unsigned short length)
  34. {
  35. digitalWrite(PIN_OUT, HIGH);
  36. delay(length);
  37. }
  38. void loop()
  39. {
  40. unsigned short i = 0;
  41. // SOS morse code: ... --- ...
  42. // S
  43. blink(dotLen);
  44. pause(elementPause);
  45. blink(dotLen);
  46. pause(elementPause);
  47. blink(dotLen);
  48. //
  49. pause(characterPause);
  50. // O
  51. blink(dashLen);
  52. pause(elementPause);
  53. blink(dashLen);
  54. pause(elementPause);
  55. blink(dashLen);
  56. //
  57. pause(characterPause);
  58. // S
  59. blink(dotLen);
  60. pause(elementPause);
  61. blink(dotLen);
  62. pause(elementPause);
  63. blink(dotLen);
  64. //
  65. pause(wordPause);
  66. }