a MIDI-to-Morse code application.
Dependencies: MIDI REnc button mbed morse
Diff: main.cpp
- Revision:
- 2:5fe4a1431347
- Parent:
- 1:d1e13b283169
- Child:
- 3:993b88218184
--- a/main.cpp Mon Jul 07 09:14:04 2014 +0000 +++ b/main.cpp Mon Jul 07 09:55:02 2014 +0000 @@ -39,6 +39,12 @@ BeepOFF(); myled = 0; } +void space(int k) +{ + wait(cw_tick * (float)k); +} + + void space1(void) { wait(cw_tick); @@ -58,7 +64,6 @@ int main() { int i; - int state; char* ptr; { @@ -68,28 +73,18 @@ while(1) { for (i = 0; i < 27; i++) { - state = ON; ptr = codes[i]; - while (*ptr) { + + for (; *ptr; ptr++, space(1) ) { switch (*ptr) { - case '-': - if (state == ON) { dash(); ++ptr; state = SPACE; } - else { space1(); state = ON; } - break; - case '.': - if (state == ON) { dot(); ++ptr; state = SPACE; } - else { space1(); state = ON; } - break; - case ' ': - if (state == ON) { space9(); ++ptr; state = SPACE; } - else { state = ON; } - break; - default: - continue; + case '-': dash(); break; + case '.': dot(); break; + case ' ': space(7); break; + default: continue; } } - space3(); + space(2); + } - } }