help :(
Dependencies: FFT
main.cpp@8:24c18eecc442, 2020-12-04 (annotated)
- Committer:
- dimitryjl23
- Date:
- Fri Dec 04 03:48:15 2020 +0000
- Revision:
- 8:24c18eecc442
- Parent:
- 7:0d62545e6d73
- Child:
- 9:97abd5e954f1
will this work?; ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
annieluo2 | 0:d6c9b09b4042 | 1 | #include "mbed.h" |
annieluo2 | 0:d6c9b09b4042 | 2 | #include "SDFileSystem.h" |
annieluo2 | 0:d6c9b09b4042 | 3 | #include "wave_player.h" |
annieluo2 | 0:d6c9b09b4042 | 4 | #include "Adafruit_LEDBackpack.h" |
annieluo2 | 0:d6c9b09b4042 | 5 | #include "Adafruit_GFX.h" |
annieluo2 | 0:d6c9b09b4042 | 6 | #include "rtos.h" |
annieluo2 | 0:d6c9b09b4042 | 7 | #include "FFT.h" |
shyamgatech | 5:598d94b45bad | 8 | #include <string> |
dimitryjl23 | 8:24c18eecc442 | 9 | #include "around_the_world-atc-array.h" |
dimitryjl23 | 8:24c18eecc442 | 10 | #include "dont_speak-no_doubt-array.h" |
dimitryjl23 | 8:24c18eecc442 | 11 | #include "my-love-array.h" |
annieluo2 | 0:d6c9b09b4042 | 12 | |
annieluo2 | 0:d6c9b09b4042 | 13 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD card |
annieluo2 | 0:d6c9b09b4042 | 14 | |
shyamgatech | 5:598d94b45bad | 15 | I2C i2c(p28, p27); // LED display |
annieluo2 | 0:d6c9b09b4042 | 16 | Adafruit_8x8matrix matrix = Adafruit_8x8matrix(&i2c); |
annieluo2 | 0:d6c9b09b4042 | 17 | |
annieluo2 | 0:d6c9b09b4042 | 18 | AnalogOut DACout(p18); // speaker |
annieluo2 | 0:d6c9b09b4042 | 19 | wave_player waver(&DACout); |
annieluo2 | 0:d6c9b09b4042 | 20 | Mutex speaker_lock; |
dimitryjl23 | 8:24c18eecc442 | 21 | Mutex file_lock; |
dimitryjl23 | 2:a6e81c45ef48 | 22 | DigitalOut myled(LED1); // mbed LED |
dimitryjl23 | 2:a6e81c45ef48 | 23 | Serial pc (USBTX,USBRX); |
shyamgatech | 5:598d94b45bad | 24 | string dir; // "/sd/" + song + ".wav" |
dimitryjl23 | 8:24c18eecc442 | 25 | //string song = "around_the_world-atc"; |
shyamgatech | 5:598d94b45bad | 26 | string song; |
dimitryjl23 | 8:24c18eecc442 | 27 | int song_data_length; |
dimitryjl23 | 8:24c18eecc442 | 28 | int song_data[]; |
dimitryjl23 | 8:24c18eecc442 | 29 | bool play = false; |
annieluo2 | 0:d6c9b09b4042 | 30 | |
annieluo2 | 0:d6c9b09b4042 | 31 | |
annieluo2 | 1:5dd6801bb0d6 | 32 | // delete later |
dimitryjl23 | 2:a6e81c45ef48 | 33 | /*int sample[12][8] = { |
shyamgatech | 5:598d94b45bad | 34 | 34085,32666,29810,29823,27514,24175,24468,32559, |
shyamgatech | 5:598d94b45bad | 35 | 36401,33075,29037,21933,20189,21751,20975,20087, |
shyamgatech | 5:598d94b45bad | 36 | 17530,27723,30891,21128,19982,15446,12413,13597, |
shyamgatech | 5:598d94b45bad | 37 | 15776,14233,15622,16334,15485,17136,16389,17954, |
shyamgatech | 5:598d94b45bad | 38 | 20349,18486,23377,34447,34400,34681,33107,31171, |
shyamgatech | 5:598d94b45bad | 39 | 30007,33640,37007,38136,39187,38169,51831,52041, |
shyamgatech | 5:598d94b45bad | 40 | 47831,48634,44189,43878,44743,46468,43170,47172, |
shyamgatech | 5:598d94b45bad | 41 | 53518,52294,54825,51992,49619,48147,47901,48413, |
shyamgatech | 5:598d94b45bad | 42 | 46049,49090,47590,46154,45423,41223,41782,54695, |
shyamgatech | 5:598d94b45bad | 43 | 57452,51210,52462,59096,56711,52268,49364,42865, |
shyamgatech | 5:598d94b45bad | 44 | 41483,37964,39215,35908,31570,28332,24492,23121, |
annieluo2 | 1:5dd6801bb0d6 | 45 | 22874,18154,15541,15263,12463,12198,13301,9951 |
dimitryjl23 | 2:a6e81c45ef48 | 46 | };*/ |
dimitryjl23 | 8:24c18eecc442 | 47 | |
dimitryjl23 | 8:24c18eecc442 | 48 | |
annieluo2 | 3:3dbf078989b1 | 49 | #define BUFFER_SIZE 64 |
annieluo2 | 1:5dd6801bb0d6 | 50 | |
annieluo2 | 1:5dd6801bb0d6 | 51 | // states for display output |
shyamgatech | 5:598d94b45bad | 52 | const int on[8][8] = { |
shyamgatech | 5:598d94b45bad | 53 | 1, 1, 1, 1, 1, 1, 1, 1, |
shyamgatech | 5:598d94b45bad | 54 | 1, 1, 1, 1, 1, 1, 1, 1, |
shyamgatech | 5:598d94b45bad | 55 | 1, 1, 1, 1, 1, 1, 1, 1, |
shyamgatech | 5:598d94b45bad | 56 | 1, 1, 1, 1, 1, 1, 1, 1, |
shyamgatech | 5:598d94b45bad | 57 | 1, 1, 1, 1, 1, 1, 1, 1, |
shyamgatech | 5:598d94b45bad | 58 | 1, 1, 1, 1, 1, 1, 1, 1, |
shyamgatech | 5:598d94b45bad | 59 | 1, 1, 1, 1, 1, 1, 1, 1, |
shyamgatech | 5:598d94b45bad | 60 | 1, 1, 1, 1, 1, 1, 1, 1 |
shyamgatech | 5:598d94b45bad | 61 | }; |
annieluo2 | 1:5dd6801bb0d6 | 62 | |
shyamgatech | 5:598d94b45bad | 63 | const int high[8][8] = { |
shyamgatech | 5:598d94b45bad | 64 | 0, 0, 0, 1, 1, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 65 | 0, 0, 0, 1, 1, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 66 | 0, 0, 1, 1, 1, 1, 0, 0, |
shyamgatech | 5:598d94b45bad | 67 | 0, 1, 1, 1, 1, 1, 1, 0, |
shyamgatech | 5:598d94b45bad | 68 | 0, 1, 1, 1, 1, 1, 1, 0, |
shyamgatech | 5:598d94b45bad | 69 | 1, 1, 1, 1, 1, 1, 1, 1, |
shyamgatech | 5:598d94b45bad | 70 | 1, 1, 1, 1, 1, 1, 1, 1, |
shyamgatech | 5:598d94b45bad | 71 | 1, 1, 1, 1, 1, 1, 1, 1 |
shyamgatech | 5:598d94b45bad | 72 | }; |
annieluo2 | 1:5dd6801bb0d6 | 73 | |
shyamgatech | 5:598d94b45bad | 74 | const int med[8][8] = { |
shyamgatech | 5:598d94b45bad | 75 | 0, 0, 0, 0, 0, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 76 | 0, 0, 0, 0, 0, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 77 | 0, 0, 0, 1, 1, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 78 | 0, 0, 1, 1, 1, 1, 0, 0, |
shyamgatech | 5:598d94b45bad | 79 | 0, 0, 1, 1, 1, 1, 0, 0, |
shyamgatech | 5:598d94b45bad | 80 | 0, 1, 1, 1, 1, 1, 1, 0, |
shyamgatech | 5:598d94b45bad | 81 | 1, 1, 1, 1, 1, 1, 1, 1, |
shyamgatech | 5:598d94b45bad | 82 | 1, 1, 1, 1, 1, 1, 1, 1 |
shyamgatech | 5:598d94b45bad | 83 | }; |
annieluo2 | 1:5dd6801bb0d6 | 84 | |
shyamgatech | 5:598d94b45bad | 85 | const int low[8][8] = { |
shyamgatech | 5:598d94b45bad | 86 | 0, 0, 0, 0, 0, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 87 | 0, 0, 0, 0, 0, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 88 | 0, 0, 0, 0, 0, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 89 | 0, 0, 0, 0, 0, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 90 | 0, 0, 0, 0, 0, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 91 | 0, 0, 1, 1, 1, 1, 0, 0, |
shyamgatech | 5:598d94b45bad | 92 | 0, 1, 1, 1, 1, 1, 1, 0, |
shyamgatech | 5:598d94b45bad | 93 | 1, 1, 1, 1, 1, 1, 1, 1 |
shyamgatech | 5:598d94b45bad | 94 | }; |
annieluo2 | 1:5dd6801bb0d6 | 95 | |
shyamgatech | 5:598d94b45bad | 96 | const int off[8][8] = { |
shyamgatech | 5:598d94b45bad | 97 | 0, 0, 0, 0, 0, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 98 | 0, 0, 0, 0, 0, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 99 | 0, 0, 0, 0, 0, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 100 | 0, 0, 0, 0, 0, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 101 | 0, 0, 0, 0, 0, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 102 | 0, 0, 0, 0, 0, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 103 | 0, 0, 0, 0, 0, 0, 0, 0, |
shyamgatech | 5:598d94b45bad | 104 | 0, 0, 0, 0, 0, 0, 0, 0 |
shyamgatech | 5:598d94b45bad | 105 | }; |
annieluo2 | 1:5dd6801bb0d6 | 106 | |
dimitryjl23 | 2:a6e81c45ef48 | 107 | |
dimitryjl23 | 2:a6e81c45ef48 | 108 | |
dimitryjl23 | 8:24c18eecc442 | 109 | |
dimitryjl23 | 8:24c18eecc442 | 110 | void display_fft(float sample[]) |
shyamgatech | 5:598d94b45bad | 111 | { |
shyamgatech | 5:598d94b45bad | 112 | |
annieluo2 | 1:5dd6801bb0d6 | 113 | int state = 0; |
annieluo2 | 3:3dbf078989b1 | 114 | float freq = 0; |
annieluo2 | 1:5dd6801bb0d6 | 115 | matrix.begin(0x70); |
shyamgatech | 5:598d94b45bad | 116 | |
shyamgatech | 5:598d94b45bad | 117 | |
dimitryjl23 | 8:24c18eecc442 | 118 | // for (int a = 0; a < 64; a++) { |
dimitryjl23 | 8:24c18eecc442 | 119 | |
dimitryjl23 | 8:24c18eecc442 | 120 | freq = sample[1]/4; |
annieluo2 | 3:3dbf078989b1 | 121 | |
dimitryjl23 | 8:24c18eecc442 | 122 | |
dimitryjl23 | 8:24c18eecc442 | 123 | //pc.printf("%f\n",freq); |
dimitryjl23 | 8:24c18eecc442 | 124 | |
dimitryjl23 | 8:24c18eecc442 | 125 | // determine state based on the FFT output range |
dimitryjl23 | 8:24c18eecc442 | 126 | if (freq < 10000) { |
dimitryjl23 | 8:24c18eecc442 | 127 | state = 5; // OFF |
dimitryjl23 | 8:24c18eecc442 | 128 | } else if (freq >= 10000 && freq < 25000) { |
dimitryjl23 | 8:24c18eecc442 | 129 | state = 4; // LOW |
dimitryjl23 | 8:24c18eecc442 | 130 | } else if (freq >= 25000 && freq < 40000) { |
dimitryjl23 | 8:24c18eecc442 | 131 | state = 3; // MED |
dimitryjl23 | 8:24c18eecc442 | 132 | } else if (freq >= 40000 && freq < 55000) { |
dimitryjl23 | 8:24c18eecc442 | 133 | state = 2; // HIGH |
dimitryjl23 | 8:24c18eecc442 | 134 | } else if (freq >= 55000) { |
dimitryjl23 | 8:24c18eecc442 | 135 | state = 1; // ON |
dimitryjl23 | 8:24c18eecc442 | 136 | } |
shyamgatech | 5:598d94b45bad | 137 | |
dimitryjl23 | 8:24c18eecc442 | 138 | // switch statement based on the state |
dimitryjl23 | 8:24c18eecc442 | 139 | switch (state) { |
dimitryjl23 | 8:24c18eecc442 | 140 | case(1): // CASE HIGHEST |
dimitryjl23 | 8:24c18eecc442 | 141 | matrix.clear(); |
dimitryjl23 | 8:24c18eecc442 | 142 | for (int i = 0; i < 8; i++) { |
dimitryjl23 | 8:24c18eecc442 | 143 | for (int j = 0; j < 8; j++) { |
dimitryjl23 | 8:24c18eecc442 | 144 | if (on[i][j] == 1) { |
dimitryjl23 | 8:24c18eecc442 | 145 | matrix.drawPixel(i, j, LED_ON); |
dimitryjl23 | 8:24c18eecc442 | 146 | } |
dimitryjl23 | 8:24c18eecc442 | 147 | } |
dimitryjl23 | 8:24c18eecc442 | 148 | } |
dimitryjl23 | 8:24c18eecc442 | 149 | matrix.writeDisplay(); |
dimitryjl23 | 8:24c18eecc442 | 150 | wait(.15); |
dimitryjl23 | 8:24c18eecc442 | 151 | break; |
dimitryjl23 | 8:24c18eecc442 | 152 | |
dimitryjl23 | 8:24c18eecc442 | 153 | case(2): // CASE HIGH |
dimitryjl23 | 8:24c18eecc442 | 154 | matrix.clear(); |
dimitryjl23 | 8:24c18eecc442 | 155 | for (int i = 0; i < 8; i++) { |
dimitryjl23 | 8:24c18eecc442 | 156 | for (int j = 0; j < 8; j++) { |
dimitryjl23 | 8:24c18eecc442 | 157 | if (high[i][j] == 1) { |
dimitryjl23 | 8:24c18eecc442 | 158 | matrix.drawPixel(i, j, LED_ON); |
annieluo2 | 1:5dd6801bb0d6 | 159 | } |
annieluo2 | 1:5dd6801bb0d6 | 160 | } |
dimitryjl23 | 8:24c18eecc442 | 161 | } |
dimitryjl23 | 8:24c18eecc442 | 162 | matrix.writeDisplay(); |
dimitryjl23 | 8:24c18eecc442 | 163 | wait(.15); |
dimitryjl23 | 8:24c18eecc442 | 164 | |
dimitryjl23 | 8:24c18eecc442 | 165 | |
shyamgatech | 5:598d94b45bad | 166 | |
dimitryjl23 | 8:24c18eecc442 | 167 | case(3): // CASE MEDIUM |
dimitryjl23 | 8:24c18eecc442 | 168 | matrix.clear(); |
dimitryjl23 | 8:24c18eecc442 | 169 | for (int i = 0; i < 8; i++) { |
dimitryjl23 | 8:24c18eecc442 | 170 | for (int j = 0; j < 8; j++) { |
dimitryjl23 | 8:24c18eecc442 | 171 | if (med[i][j] == 1) { |
dimitryjl23 | 8:24c18eecc442 | 172 | matrix.drawPixel(i, j, LED_ON); |
annieluo2 | 1:5dd6801bb0d6 | 173 | } |
annieluo2 | 1:5dd6801bb0d6 | 174 | } |
dimitryjl23 | 8:24c18eecc442 | 175 | } |
dimitryjl23 | 8:24c18eecc442 | 176 | matrix.writeDisplay(); |
dimitryjl23 | 8:24c18eecc442 | 177 | wait(.15); |
dimitryjl23 | 8:24c18eecc442 | 178 | break; |
shyamgatech | 5:598d94b45bad | 179 | |
dimitryjl23 | 8:24c18eecc442 | 180 | case(4): // CASE LOW |
dimitryjl23 | 8:24c18eecc442 | 181 | matrix.clear(); |
dimitryjl23 | 8:24c18eecc442 | 182 | for (int i = 0; i < 8; i++) { |
dimitryjl23 | 8:24c18eecc442 | 183 | for (int j = 0; j < 8; j++) { |
dimitryjl23 | 8:24c18eecc442 | 184 | if (low[i][j] == 1) { |
dimitryjl23 | 8:24c18eecc442 | 185 | matrix.drawPixel(i, j, LED_ON); |
annieluo2 | 1:5dd6801bb0d6 | 186 | } |
annieluo2 | 1:5dd6801bb0d6 | 187 | } |
dimitryjl23 | 8:24c18eecc442 | 188 | } |
dimitryjl23 | 8:24c18eecc442 | 189 | matrix.writeDisplay(); |
dimitryjl23 | 8:24c18eecc442 | 190 | wait(.15); |
dimitryjl23 | 8:24c18eecc442 | 191 | break; |
shyamgatech | 5:598d94b45bad | 192 | |
dimitryjl23 | 8:24c18eecc442 | 193 | case(5): // CASE OFF |
dimitryjl23 | 8:24c18eecc442 | 194 | matrix.clear(); |
dimitryjl23 | 8:24c18eecc442 | 195 | for (int i = 0; i < 8; i++) { |
dimitryjl23 | 8:24c18eecc442 | 196 | for (int j = 0; j < 8; j++) { |
dimitryjl23 | 8:24c18eecc442 | 197 | if (off[i][j] == 1) { |
dimitryjl23 | 8:24c18eecc442 | 198 | matrix.drawPixel(i, j, LED_ON); |
annieluo2 | 1:5dd6801bb0d6 | 199 | } |
annieluo2 | 1:5dd6801bb0d6 | 200 | } |
dimitryjl23 | 8:24c18eecc442 | 201 | } |
dimitryjl23 | 8:24c18eecc442 | 202 | matrix.writeDisplay(); |
dimitryjl23 | 8:24c18eecc442 | 203 | wait(.15); |
dimitryjl23 | 8:24c18eecc442 | 204 | break; |
shyamgatech | 5:598d94b45bad | 205 | |
dimitryjl23 | 8:24c18eecc442 | 206 | default: |
dimitryjl23 | 8:24c18eecc442 | 207 | break; |
shyamgatech | 5:598d94b45bad | 208 | } |
shyamgatech | 5:598d94b45bad | 209 | |
dimitryjl23 | 8:24c18eecc442 | 210 | //} |
dimitryjl23 | 8:24c18eecc442 | 211 | |
dimitryjl23 | 8:24c18eecc442 | 212 | //pc.printf("done"); |
dimitryjl23 | 8:24c18eecc442 | 213 | |
dimitryjl23 | 2:a6e81c45ef48 | 214 | } |
dimitryjl23 | 2:a6e81c45ef48 | 215 | |
dimitryjl23 | 2:a6e81c45ef48 | 216 | //Reads SD card and passes value to frequency display |
dimitryjl23 | 2:a6e81c45ef48 | 217 | void display_thread(void const* args) |
dimitryjl23 | 2:a6e81c45ef48 | 218 | { |
dimitryjl23 | 8:24c18eecc442 | 219 | while(1) { |
shyamgatech | 5:598d94b45bad | 220 | |
dimitryjl23 | 8:24c18eecc442 | 221 | float buffer[BUFFER_SIZE]; |
dimitryjl23 | 8:24c18eecc442 | 222 | int buffer_index = 0; |
dimitryjl23 | 8:24c18eecc442 | 223 | |
dimitryjl23 | 8:24c18eecc442 | 224 | //int num_elements = NUM_ELEMENTS_AROUND_THE_WORLD; |
dimitryjl23 | 8:24c18eecc442 | 225 | int num_elements = 16979; |
dimitryjl23 | 8:24c18eecc442 | 226 | for(int i=0; i<num_elements; ++i ) { |
dimitryjl23 | 8:24c18eecc442 | 227 | buffer[buffer_index] = song_data[i]; |
dimitryjl23 | 8:24c18eecc442 | 228 | // pc.printf("%f", buffer[buffer_index]); |
dimitryjl23 | 8:24c18eecc442 | 229 | buffer_index++; |
dimitryjl23 | 8:24c18eecc442 | 230 | //pc.printf("%d\n",value); |
dimitryjl23 | 8:24c18eecc442 | 231 | //buffer_index++; |
dimitryjl23 | 8:24c18eecc442 | 232 | if(buffer_index == BUFFER_SIZE) { |
dimitryjl23 | 8:24c18eecc442 | 233 | //fast fourier tranform function here |
dimitryjl23 | 8:24c18eecc442 | 234 | vRealFFT(buffer, 4); |
dimitryjl23 | 8:24c18eecc442 | 235 | display_fft(buffer); |
dimitryjl23 | 8:24c18eecc442 | 236 | buffer_index = 0; |
dimitryjl23 | 8:24c18eecc442 | 237 | memset(buffer,0,sizeof(buffer)); |
dimitryjl23 | 8:24c18eecc442 | 238 | |
dimitryjl23 | 8:24c18eecc442 | 239 | } |
shyamgatech | 5:598d94b45bad | 240 | |
shyamgatech | 5:598d94b45bad | 241 | } |
annieluo2 | 3:3dbf078989b1 | 242 | |
dimitryjl23 | 8:24c18eecc442 | 243 | Thread::wait(300); |
dimitryjl23 | 2:a6e81c45ef48 | 244 | } |
shyamgatech | 5:598d94b45bad | 245 | |
annieluo2 | 0:d6c9b09b4042 | 246 | } |
annieluo2 | 0:d6c9b09b4042 | 247 | |
annieluo2 | 0:d6c9b09b4042 | 248 | void speaker_thread(void const* args) |
annieluo2 | 0:d6c9b09b4042 | 249 | { |
shyamgatech | 5:598d94b45bad | 250 | while(1) { |
annieluo2 | 1:5dd6801bb0d6 | 251 | // check helper function for new song in GUI |
annieluo2 | 0:d6c9b09b4042 | 252 | // grab file here and put together string |
annieluo2 | 0:d6c9b09b4042 | 253 | // string song_title = "/sd/" + "" + ".wav"; |
shyamgatech | 5:598d94b45bad | 254 | |
shyamgatech | 5:598d94b45bad | 255 | |
dimitryjl23 | 8:24c18eecc442 | 256 | if(play == true) |
dimitryjl23 | 8:24c18eecc442 | 257 | { |
dimitryjl23 | 8:24c18eecc442 | 258 | //speaker_lock.lock(); |
annieluo2 | 0:d6c9b09b4042 | 259 | FILE *wave_file; |
shyamgatech | 5:598d94b45bad | 260 | dir = "/sd/" + song + ".wav"; |
dimitryjl23 | 8:24c18eecc442 | 261 | |
dimitryjl23 | 8:24c18eecc442 | 262 | file_lock.lock(); |
shyamgatech | 5:598d94b45bad | 263 | wave_file=fopen(dir.c_str(),"r"); |
dimitryjl23 | 8:24c18eecc442 | 264 | file_lock.unlock(); |
dimitryjl23 | 8:24c18eecc442 | 265 | |
dimitryjl23 | 8:24c18eecc442 | 266 | waver.play(wave_file); |
shyamgatech | 5:598d94b45bad | 267 | |
dimitryjl23 | 8:24c18eecc442 | 268 | file_lock.lock(); |
annieluo2 | 0:d6c9b09b4042 | 269 | fclose(wave_file); |
dimitryjl23 | 8:24c18eecc442 | 270 | file_lock.unlock(); |
dimitryjl23 | 8:24c18eecc442 | 271 | //speaker_lock.unlock(); |
dimitryjl23 | 8:24c18eecc442 | 272 | } |
dimitryjl23 | 8:24c18eecc442 | 273 | Thread::wait(1000); |
annieluo2 | 0:d6c9b09b4042 | 274 | } |
annieluo2 | 0:d6c9b09b4042 | 275 | } |
shyamgatech | 5:598d94b45bad | 276 | |
annieluo2 | 0:d6c9b09b4042 | 277 | |
annieluo2 | 0:d6c9b09b4042 | 278 | int main() |
annieluo2 | 0:d6c9b09b4042 | 279 | { |
dimitryjl23 | 8:24c18eecc442 | 280 | //sd.mount(); |
dimitryjl23 | 8:24c18eecc442 | 281 | pc.printf("I have updated\n"); |
annieluo2 | 0:d6c9b09b4042 | 282 | Thread th1(speaker_thread); |
annieluo2 | 1:5dd6801bb0d6 | 283 | Thread th2(display_thread); |
shyamgatech | 5:598d94b45bad | 284 | char c; |
annieluo2 | 0:d6c9b09b4042 | 285 | while(1) { |
dimitryjl23 | 8:24c18eecc442 | 286 | /*myled = 1; |
annieluo2 | 1:5dd6801bb0d6 | 287 | wait(0.2); |
annieluo2 | 1:5dd6801bb0d6 | 288 | myled = 0; |
annieluo2 | 1:5dd6801bb0d6 | 289 | wait(0.2); |
dimitryjl23 | 8:24c18eecc442 | 290 | */ |
shyamgatech | 5:598d94b45bad | 291 | while(!pc.readable()) { |
shyamgatech | 5:598d94b45bad | 292 | Thread::wait(1); |
shyamgatech | 5:598d94b45bad | 293 | } |
shyamgatech | 5:598d94b45bad | 294 | if (pc.getc() == '!') { |
shyamgatech | 5:598d94b45bad | 295 | c = pc.getc(); |
shyamgatech | 5:598d94b45bad | 296 | switch(c) { |
shyamgatech | 5:598d94b45bad | 297 | case '1': |
shyamgatech | 5:598d94b45bad | 298 | song = "africa-toto"; |
dimitryjl23 | 8:24c18eecc442 | 299 | |
shyamgatech | 5:598d94b45bad | 300 | break; |
shyamgatech | 5:598d94b45bad | 301 | case '2': |
shyamgatech | 5:598d94b45bad | 302 | song = "around_the_world-atc"; |
dimitryjl23 | 8:24c18eecc442 | 303 | song_data_length = NUM_ELEMENTS_AROUND_THE_WORLD; |
dimitryjl23 | 8:24c18eecc442 | 304 | song_data = data_around_the_world; |
shyamgatech | 5:598d94b45bad | 305 | break; |
shyamgatech | 5:598d94b45bad | 306 | case '3': |
shyamgatech | 5:598d94b45bad | 307 | song = "beautiful_life-ace_of_base"; |
shyamgatech | 5:598d94b45bad | 308 | break; |
shyamgatech | 5:598d94b45bad | 309 | case '4': |
shyamgatech | 5:598d94b45bad | 310 | song = "dont_speak-no_doubt"; |
dimitryjl23 | 8:24c18eecc442 | 311 | song_data_length = NUM_ELEMENTS_DONT_SPEAK_NO_DOUBT; |
dimitryjl23 | 8:24c18eecc442 | 312 | song_data = data_dont_speak_no_doubt; |
shyamgatech | 5:598d94b45bad | 313 | break; |
shyamgatech | 5:598d94b45bad | 314 | case '5': |
shyamgatech | 5:598d94b45bad | 315 | song = "my-love"; |
dimitryjl23 | 8:24c18eecc442 | 316 | song_data_length = NUM_ELEMENTS_MY_LOVE; |
dimitryjl23 | 8:24c18eecc442 | 317 | song_data = data_my_love; |
shyamgatech | 5:598d94b45bad | 318 | break; |
shyamgatech | 5:598d94b45bad | 319 | case '6': |
shyamgatech | 5:598d94b45bad | 320 | song = "Song1_test"; |
shyamgatech | 5:598d94b45bad | 321 | break; |
shyamgatech | 5:598d94b45bad | 322 | case 'P': |
shyamgatech | 5:598d94b45bad | 323 | // wave_player plays |
shyamgatech | 5:598d94b45bad | 324 | play = true; |
dimitryjl23 | 8:24c18eecc442 | 325 | led =1; |
shyamgatech | 5:598d94b45bad | 326 | break; |
shyamgatech | 5:598d94b45bad | 327 | case 'S': |
shyamgatech | 5:598d94b45bad | 328 | // wave_player stops |
shyamgatech | 5:598d94b45bad | 329 | play = false; |
dimitryjl23 | 8:24c18eecc442 | 330 | //led = 0; |
shyamgatech | 5:598d94b45bad | 331 | break; |
shyamgatech | 5:598d94b45bad | 332 | default: |
shyamgatech | 5:598d94b45bad | 333 | break; |
shyamgatech | 5:598d94b45bad | 334 | } |
shyamgatech | 5:598d94b45bad | 335 | } |
annieluo2 | 0:d6c9b09b4042 | 336 | Thread::wait(100); |
annieluo2 | 0:d6c9b09b4042 | 337 | } |
shyamgatech | 5:598d94b45bad | 338 | |
annieluo2 | 0:d6c9b09b4042 | 339 | } |