a MIDI-to-Morse code application.
Dependencies: MIDI REnc button mbed morse
main.cpp
- Committer:
- ChuckTimber
- Date:
- 2014-07-07
- Revision:
- 1:d1e13b283169
- Parent:
- 0:d0ebbde59857
- Child:
- 2:5fe4a1431347
File content as of revision 1:d1e13b283169:
#include "mbed.h" #define FREQ 800 DigitalOut myled(LED1); char* codes[] = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", " " }; char* nums[] = { "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----." }; 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 space1(void) { wait(cw_tick); } void space3(void) { wait(cw_tick*3); } void space9(void) { wait(cw_tick*9); } enum { ON, SPACE }; int main() { int i; int state; char* ptr; { __pwm.period(1.0/FREQ); __pwm.write(0.0); }; while(1) { for (i = 0; i < 27; i++) { state = ON; ptr = codes[i]; while (*ptr) { 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; } } space3(); } } }