a MIDI-to-Morse code application.

Dependencies:   MIDI REnc button mbed morse

Revision:
6:7405805be717
Parent:
5:decb31e2efa4
Child:
7:82910f3806b3
--- a/main.cpp	Sun Jul 13 05:12:31 2014 +0000
+++ b/main.cpp	Sun Jul 13 09:26:49 2014 +0000
@@ -1,8 +1,6 @@
 #include "mbed.h"
 #include "button.h"
-
-#define FREQ 800
-DigitalOut myled(LED1);
+#include "morse.h"
 
 char* codes[] = { ".-", "-...", "-.-.", "-..", ".",
                   "..-.", "--.", "....", "..", ".---",
@@ -31,56 +29,17 @@
                   "........" // 'HH'
                 };
 
-float cw_tick = 0.1;
-
-PwmOut __pwm( dp24 );
-
-void BeepOFF (void)
-{
-    __pwm.write(0.0);
-}
-
-void BeepON (void)
-{
-    __pwm.write(0.5);
-}
-
-void dot (void)
-{
-    BeepON();
-    myled = 1;
-    wait(cw_tick);
-    BeepOFF();
-    myled = 0;
-}
-
-void dash (void)
-{
-    BeepON();
-    myled = 1;
-    wait(cw_tick*3);
-    BeepOFF();
-    myled = 0;
-}
-
-void space(int k)
-{
-    wait(cw_tick * (float)k);
-}
 
 
-
-    BTN btn(dp13);
+BTN btn(dp13);
+Morse morse;
+//Morse morse(dp24, LED1);
+//Morse morse(dp24, LED1, 0.08, 1000);
 
 int main()
 {
     int i;
-    char* ptr;
 
-    {
-        __pwm.period(1.0/FREQ);
-        __pwm.write(0.0);
-    };
 
     btn.CMD = 0;
     while(1) {
@@ -91,23 +50,7 @@
                 btn.CMD = 0;
             }
 
-            ptr = codes[i];
-            for (; *ptr; ptr++, space(1) ) {
-                switch (*ptr) {
-                    case '-':
-                        dash();
-                        break;
-                    case '.':
-                        dot();
-                        break;
-                    case ' ':
-                        space(7);
-                        break;
-                    default:
-                        continue;
-                }
-            }
-            space(2);
+            morse.code(codes[i]);
 
         }
     }