a MIDI-to-Morse code application.

Dependencies:   MIDI REnc button mbed morse

Committer:
ChuckTimber
Date:
Sat Jul 26 22:49:43 2014 +0000
Revision:
9:09fc839da416
Parent:
8:96f4614a46ba
Child:
10:57bbdc516590
rotary encoder introduced

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 9:09fc839da416 3 #include "REnc.h"
ChuckTimber 6:7405805be717 4 #include "morse.h"
ChuckTimber 8:96f4614a46ba 5 #include "MIDI.h"
ChuckTimber 0:d0ebbde59857 6
ChuckTimber 9:09fc839da416 7 // alphabet 26-charactor + 1-space
ChuckTimber 3:993b88218184 8 char* codes[] = { ".-", "-...", "-.-.", "-..", ".",
ChuckTimber 0:d0ebbde59857 9 "..-.", "--.", "....", "..", ".---",
ChuckTimber 3:993b88218184 10 "-.-", ".-..", "--", "-.", "---",
ChuckTimber 0:d0ebbde59857 11 ".--.", "--.-", ".-.", "...", "-",
ChuckTimber 3:993b88218184 12 "..-", "...-", ".--", "-..-", "-.--", "--..", " "
ChuckTimber 3:993b88218184 13 };
ChuckTimber 9:09fc839da416 14
ChuckTimber 9:09fc839da416 15 // 10-number
ChuckTimber 0:d0ebbde59857 16 char* nums[] = { "-----", ".----", "..---", "...--", "....-",
ChuckTimber 3:993b88218184 17 ".....", "-....", "--...", "---..", "----."
ChuckTimber 3:993b88218184 18 };
ChuckTimber 3:993b88218184 19
ChuckTimber 9:09fc839da416 20 // 15-marks
ChuckTimber 3:993b88218184 21 char* marks[] = { ".-.-.-", // '.'
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 ".-..-.", // '"'
ChuckTimber 3:993b88218184 32 ".-.-.", // '+'
ChuckTimber 3:993b88218184 33 ".----.", // '''
ChuckTimber 3:993b88218184 34 "---...", // ':'
ChuckTimber 3:993b88218184 35 "........" // 'HH'
ChuckTimber 3:993b88218184 36 };
ChuckTimber 0:d0ebbde59857 37
ChuckTimber 9:09fc839da416 38 // 6-hybrid
ChuckTimber 9:09fc839da416 39 char* hybrid[] = { ".-...", // 'AS'
ChuckTimber 9:09fc839da416 40 ".-.-.", // 'AR'
ChuckTimber 9:09fc839da416 41 "-...-.-", // 'BK'
ChuckTimber 9:09fc839da416 42 "-...-", // 'BT'
ChuckTimber 9:09fc839da416 43 "-.--.", // 'KN'
ChuckTimber 9:09fc839da416 44 "...-.-" // 'VA'
ChuckTimber 9:09fc839da416 45 };
ChuckTimber 9:09fc839da416 46
ChuckTimber 8:96f4614a46ba 47
ChuckTimber 8:96f4614a46ba 48
ChuckTimber 8:96f4614a46ba 49 void proc_NoteOn(byte channel, byte note, byte velocity);
ChuckTimber 8:96f4614a46ba 50 void proc_ControlChange(byte channel, byte number, byte value);
ChuckTimber 9:09fc839da416 51 void proc_REnc_right(void);
ChuckTimber 9:09fc839da416 52 void proc_REnc_left(void);
ChuckTimber 2:5fe4a1431347 53
ChuckTimber 2:5fe4a1431347 54
ChuckTimber 6:7405805be717 55 BTN btn(dp13);
ChuckTimber 6:7405805be717 56 Morse morse;
ChuckTimber 8:96f4614a46ba 57 MIDI midi(dp16, dp15);
ChuckTimber 9:09fc839da416 58 REnc renc(dp1, dp2);
ChuckTimber 0:d0ebbde59857 59
ChuckTimber 3:993b88218184 60 int main()
ChuckTimber 0:d0ebbde59857 61 {
ChuckTimber 0:d0ebbde59857 62 int i;
ChuckTimber 7:82910f3806b3 63 int mode = 0;
ChuckTimber 7:82910f3806b3 64 int value;
ChuckTimber 0:d0ebbde59857 65
ChuckTimber 8:96f4614a46ba 66 //Morse morse(dp24, LED1);
ChuckTimber 8:96f4614a46ba 67 //Morse morse(dp24, LED1, 0.08, 1000);
ChuckTimber 8:96f4614a46ba 68
ChuckTimber 8:96f4614a46ba 69 midi.setHandleNoteOn(&proc_NoteOn);
ChuckTimber 8:96f4614a46ba 70 midi.setHandleControlChange(&proc_ControlChange);
ChuckTimber 9:09fc839da416 71
ChuckTimber 9:09fc839da416 72 renc.setHandleRight(&proc_REnc_right);
ChuckTimber 9:09fc839da416 73 renc.setHandleLeft(&proc_REnc_left);
ChuckTimber 8:96f4614a46ba 74
ChuckTimber 8:96f4614a46ba 75 midi.begin();
ChuckTimber 8:96f4614a46ba 76 wait(1.0);
ChuckTimber 5:decb31e2efa4 77 btn.CMD = 0;
ChuckTimber 8:96f4614a46ba 78
ChuckTimber 0:d0ebbde59857 79 while(1) {
ChuckTimber 8:96f4614a46ba 80 midi.read();
ChuckTimber 9:09fc839da416 81 /*
ChuckTimber 9:09fc839da416 82 if (renc.CMD == FORWARD) {
ChuckTimber 9:09fc839da416 83 morse.incidx();
ChuckTimber 9:09fc839da416 84 renc.CMD = IDLE;
ChuckTimber 9:09fc839da416 85 } else if (renc.CMD == BACKWARD) {
ChuckTimber 9:09fc839da416 86 morse.decidx();
ChuckTimber 9:09fc839da416 87 renc.CMD = IDLE;
ChuckTimber 9:09fc839da416 88 }
ChuckTimber 9:09fc839da416 89 */
ChuckTimber 7:82910f3806b3 90 if(btn.CMD) {
ChuckTimber 7:82910f3806b3 91 mode++;
ChuckTimber 7:82910f3806b3 92 btn.CMD = 0;
ChuckTimber 8:96f4614a46ba 93 srand( time(NULL) );
ChuckTimber 7:82910f3806b3 94 }
ChuckTimber 7:82910f3806b3 95 if (mode % 2) {
ChuckTimber 7:82910f3806b3 96 for (i = 0; i < 5; i++) {
ChuckTimber 7:82910f3806b3 97 value = rand();
ChuckTimber 7:82910f3806b3 98 morse.code(codes[value % 26]);
ChuckTimber 5:decb31e2efa4 99 }
ChuckTimber 7:82910f3806b3 100 morse.code(codes[26]);
ChuckTimber 0:d0ebbde59857 101 }
ChuckTimber 0:d0ebbde59857 102 }
ChuckTimber 0:d0ebbde59857 103 }
ChuckTimber 8:96f4614a46ba 104
ChuckTimber 8:96f4614a46ba 105 void proc_NoteOn(byte channel, byte note, byte velocity)
ChuckTimber 8:96f4614a46ba 106 {
ChuckTimber 8:96f4614a46ba 107 if ((36 <= note) && (note <= 36+26)) {
ChuckTimber 8:96f4614a46ba 108 morse.code(codes[note - 36]);
ChuckTimber 8:96f4614a46ba 109 }
ChuckTimber 8:96f4614a46ba 110 }
ChuckTimber 8:96f4614a46ba 111
ChuckTimber 8:96f4614a46ba 112 void proc_ControlChange(byte channel, byte number, byte value)
ChuckTimber 8:96f4614a46ba 113 {
ChuckTimber 8:96f4614a46ba 114 if (number == 16) { // General Purpose Controller 1
ChuckTimber 9:09fc839da416 115 morse.setidx(value);
ChuckTimber 8:96f4614a46ba 116 }
ChuckTimber 9:09fc839da416 117 }
ChuckTimber 9:09fc839da416 118
ChuckTimber 9:09fc839da416 119 void proc_REnc_right(void)
ChuckTimber 9:09fc839da416 120 {
ChuckTimber 9:09fc839da416 121 morse.incidx();
ChuckTimber 9:09fc839da416 122 }
ChuckTimber 9:09fc839da416 123
ChuckTimber 9:09fc839da416 124 void proc_REnc_left(void)
ChuckTimber 9:09fc839da416 125 {
ChuckTimber 9:09fc839da416 126 morse.decidx();
ChuckTimber 9:09fc839da416 127 }