Brent Palermo / Mbed 2 deprecated Nucleo_Morse

Dependencies:   mbed

Revision:
0:dd9902e15aca
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri May 30 13:40:51 2014 +0000
@@ -0,0 +1,166 @@
+//Flashes a pattern of morse code on LED1 based on the input string
+//Change the "text" string to alter the message.  Lower case, spaces, and numbers only.
+//Change the value of "t" to change the message speed.
+
+#include "mbed.h"
+#include "string"
+
+DigitalOut led(LED1);
+
+int main()
+{
+    while(1) {
+        //Create a blank string for morse code
+        string morse;
+
+        //Record the message into a string
+        string text ("test test 0123456789");
+
+        //Set the morse code blink time constant
+        double t = 0.1;
+
+        //Cut the string of letters into a string of morse code
+        for (int i=0; i<text.length(); ++i) {
+            switch (text.at(i)) {
+                case 'a':
+                    morse.append(".-");
+                    break;
+                case 'b':
+                    morse.append("-...");
+                    break;
+                case 'c':
+                    morse.append("-.-.");
+                    break;
+                case 'd':
+                    morse.append("-..");
+                    break;
+                case 'e':
+                    morse.append(".");
+                    break;
+                case 'f':
+                    morse.append("..-.");
+                    break;
+                case 'g':
+                    morse.append("--.");
+                    break;
+                case 'h':
+                    morse.append("....");
+                    break;
+                case 'i':
+                    morse.append("..");
+                    break;
+                case 'j':
+                    morse.append(".---");
+                    break;
+                case 'k':
+                    morse.append("-.-");
+                    break;
+                case 'l':
+                    morse.append(".-..");
+                    break;
+                case 'm':
+                    morse.append("--");
+                    break;
+                case 'n':
+                    morse.append("-.");
+                    break;
+                case 'o':
+                    morse.append("---");
+                    break;
+                case 'p':
+                    morse.append(".--.");
+                    break;
+                case 'q':
+                    morse.append("--.-");
+                    break;
+                case 'r':
+                    morse.append(".-.");
+                    break;
+                case 's':
+                    morse.append("...");
+                    break;
+                case 't':
+                    morse.append("-");
+                    break;
+                case 'u':
+                    morse.append("..-");
+                    break;
+                case 'v':
+                    morse.append("...-");
+                    break;
+                case 'w':
+                    morse.append(".--");
+                    break;
+                case 'x':
+                    morse.append("-..-");
+                    break;
+                case 'y':
+                    morse.append("-.--");
+                    break;
+                case 'z':
+                    morse.append("--..");
+                    break;
+                case ' ':
+                    morse.append(" ");
+                    break;
+                case '1':
+                    morse.append(".----");
+                    break;
+                case '2':
+                    morse.append("..---");
+                    break;
+                case '3':
+                    morse.append("...--");
+                    break;
+                case '4':
+                    morse.append("....-");
+                    break;
+                case '5':
+                    morse.append(".....");
+                    break;
+                case '6':
+                    morse.append("-....");
+                    break;
+                case '7':
+                    morse.append("--...");
+                    break;
+                case '8':
+                    morse.append("---..");
+                    break;
+                case '9':
+                    morse.append("----.");
+                    break;
+                case '0':
+                    morse.append("-----");
+            }
+
+            morse.append("_");
+        }
+
+        //Blink the LED in morse code
+        for (int j=0 ; j<morse.length() ; ++j) {
+            switch (morse.at(j)) {
+                case '.':
+                    led = 1;
+                    wait(t);
+                    led = 0;
+                    wait(t);
+                    break;
+                case '-':
+                    led = 1;
+                    wait(3*t);
+                    led = 0;
+                    wait(t);
+                    break;
+                case '_':
+                    wait(3*t);
+                    break;
+                case ' ':
+                    wait(4*t);
+            }
+        }
+
+        //Wait 2 seconds before repeating the message
+        wait(2);
+    }
+}