this hurts

Dependencies:   FFT

Committer:
shyamgatech
Date:
Thu Dec 03 18:15:35 2020 +0000
Revision:
7:0d62545e6d73
Parent:
6:d311a95f1e9b
Parent:
4:7974ef1b1e07
addded gui mbed code;

Who changed what in which revision?

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