a MIDI-to-Morse code application.

Dependencies:   MIDI REnc button mbed morse

Committer:
ChuckTimber
Date:
Sun Jul 13 05:12:31 2014 +0000
Revision:
5:decb31e2efa4
Parent:
4:98b4e2f46789
Child:
6:7405805be717
button lib version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ChuckTimber 0:d0ebbde59857 1 #include "mbed.h"
ChuckTimber 5:decb31e2efa4 2 #include "button.h"
ChuckTimber 3:993b88218184 3
ChuckTimber 0:d0ebbde59857 4 #define FREQ 800
ChuckTimber 0:d0ebbde59857 5 DigitalOut myled(LED1);
ChuckTimber 0:d0ebbde59857 6
ChuckTimber 3:993b88218184 7 char* codes[] = { ".-", "-...", "-.-.", "-..", ".",
ChuckTimber 0:d0ebbde59857 8 "..-.", "--.", "....", "..", ".---",
ChuckTimber 3:993b88218184 9 "-.-", ".-..", "--", "-.", "---",
ChuckTimber 0:d0ebbde59857 10 ".--.", "--.-", ".-.", "...", "-",
ChuckTimber 3:993b88218184 11 "..-", "...-", ".--", "-..-", "-.--", "--..", " "
ChuckTimber 3:993b88218184 12 };
ChuckTimber 0:d0ebbde59857 13 char* nums[] = { "-----", ".----", "..---", "...--", "....-",
ChuckTimber 3:993b88218184 14 ".....", "-....", "--...", "---..", "----."
ChuckTimber 3:993b88218184 15 };
ChuckTimber 3:993b88218184 16
ChuckTimber 3:993b88218184 17 char* marks[] = { ".-.-.-", // '.'
ChuckTimber 3:993b88218184 18 "--..--", // ','
ChuckTimber 3:993b88218184 19 "..--..", // '?'
ChuckTimber 3:993b88218184 20 "-.-.--", // '!'
ChuckTimber 3:993b88218184 21 "-....-", // '-'
ChuckTimber 3:993b88218184 22 "-..-.", // '/'
ChuckTimber 3:993b88218184 23 ".--.-.", // '@'
ChuckTimber 3:993b88218184 24 "-.--.", // '('
ChuckTimber 3:993b88218184 25 "-.--.-", // ')'
ChuckTimber 3:993b88218184 26 "-...-", // '='
ChuckTimber 3:993b88218184 27 ".-..-.", // '"'
ChuckTimber 3:993b88218184 28 ".-.-.", // '+'
ChuckTimber 3:993b88218184 29 ".----.", // '''
ChuckTimber 3:993b88218184 30 "---...", // ':'
ChuckTimber 3:993b88218184 31 "........" // 'HH'
ChuckTimber 3:993b88218184 32 };
ChuckTimber 0:d0ebbde59857 33
ChuckTimber 0:d0ebbde59857 34 float cw_tick = 0.1;
ChuckTimber 0:d0ebbde59857 35
ChuckTimber 0:d0ebbde59857 36 PwmOut __pwm( dp24 );
ChuckTimber 0:d0ebbde59857 37
ChuckTimber 0:d0ebbde59857 38 void BeepOFF (void)
ChuckTimber 0:d0ebbde59857 39 {
ChuckTimber 0:d0ebbde59857 40 __pwm.write(0.0);
ChuckTimber 0:d0ebbde59857 41 }
ChuckTimber 0:d0ebbde59857 42
ChuckTimber 0:d0ebbde59857 43 void BeepON (void)
ChuckTimber 0:d0ebbde59857 44 {
ChuckTimber 0:d0ebbde59857 45 __pwm.write(0.5);
ChuckTimber 0:d0ebbde59857 46 }
ChuckTimber 0:d0ebbde59857 47
ChuckTimber 0:d0ebbde59857 48 void dot (void)
ChuckTimber 0:d0ebbde59857 49 {
ChuckTimber 3:993b88218184 50 BeepON();
ChuckTimber 3:993b88218184 51 myled = 1;
ChuckTimber 0:d0ebbde59857 52 wait(cw_tick);
ChuckTimber 3:993b88218184 53 BeepOFF();
ChuckTimber 3:993b88218184 54 myled = 0;
ChuckTimber 0:d0ebbde59857 55 }
ChuckTimber 0:d0ebbde59857 56
ChuckTimber 0:d0ebbde59857 57 void dash (void)
ChuckTimber 0:d0ebbde59857 58 {
ChuckTimber 3:993b88218184 59 BeepON();
ChuckTimber 3:993b88218184 60 myled = 1;
ChuckTimber 0:d0ebbde59857 61 wait(cw_tick*3);
ChuckTimber 3:993b88218184 62 BeepOFF();
ChuckTimber 3:993b88218184 63 myled = 0;
ChuckTimber 0:d0ebbde59857 64 }
ChuckTimber 0:d0ebbde59857 65
ChuckTimber 2:5fe4a1431347 66 void space(int k)
ChuckTimber 2:5fe4a1431347 67 {
ChuckTimber 2:5fe4a1431347 68 wait(cw_tick * (float)k);
ChuckTimber 2:5fe4a1431347 69 }
ChuckTimber 2:5fe4a1431347 70
ChuckTimber 2:5fe4a1431347 71
ChuckTimber 4:98b4e2f46789 72
ChuckTimber 4:98b4e2f46789 73 BTN btn(dp13);
ChuckTimber 0:d0ebbde59857 74
ChuckTimber 3:993b88218184 75 int main()
ChuckTimber 0:d0ebbde59857 76 {
ChuckTimber 0:d0ebbde59857 77 int i;
ChuckTimber 0:d0ebbde59857 78 char* ptr;
ChuckTimber 0:d0ebbde59857 79
ChuckTimber 0:d0ebbde59857 80 {
ChuckTimber 0:d0ebbde59857 81 __pwm.period(1.0/FREQ);
ChuckTimber 0:d0ebbde59857 82 __pwm.write(0.0);
ChuckTimber 0:d0ebbde59857 83 };
ChuckTimber 0:d0ebbde59857 84
ChuckTimber 5:decb31e2efa4 85 btn.CMD = 0;
ChuckTimber 0:d0ebbde59857 86 while(1) {
ChuckTimber 5:decb31e2efa4 87 for (i = 0; i < 27; i++) {
ChuckTimber 5:decb31e2efa4 88
ChuckTimber 5:decb31e2efa4 89 if(btn.CMD) {
ChuckTimber 5:decb31e2efa4 90 i = 0;
ChuckTimber 5:decb31e2efa4 91 btn.CMD = 0;
ChuckTimber 5:decb31e2efa4 92 }
ChuckTimber 5:decb31e2efa4 93
ChuckTimber 1:d1e13b283169 94 ptr = codes[i];
ChuckTimber 2:5fe4a1431347 95 for (; *ptr; ptr++, space(1) ) {
ChuckTimber 0:d0ebbde59857 96 switch (*ptr) {
ChuckTimber 3:993b88218184 97 case '-':
ChuckTimber 3:993b88218184 98 dash();
ChuckTimber 3:993b88218184 99 break;
ChuckTimber 3:993b88218184 100 case '.':
ChuckTimber 3:993b88218184 101 dot();
ChuckTimber 3:993b88218184 102 break;
ChuckTimber 3:993b88218184 103 case ' ':
ChuckTimber 3:993b88218184 104 space(7);
ChuckTimber 3:993b88218184 105 break;
ChuckTimber 3:993b88218184 106 default:
ChuckTimber 3:993b88218184 107 continue;
ChuckTimber 0:d0ebbde59857 108 }
ChuckTimber 0:d0ebbde59857 109 }
ChuckTimber 2:5fe4a1431347 110 space(2);
ChuckTimber 2:5fe4a1431347 111
ChuckTimber 0:d0ebbde59857 112 }
ChuckTimber 0:d0ebbde59857 113 }
ChuckTimber 0:d0ebbde59857 114 }