koikelab / Mbed 2 deprecated app-board-Speaker

Dependencies:   C12832 USBHost mbed MMA7660 wave_player

Fork of app-board-Speaker by Ryohei Funakoshi

Committer:
toyohara
Date:
Tue Dec 13 08:02:54 2016 +0000
Revision:
15:46ca600425fc
Parent:
14:3b123bcdd79c
Child:
16:12f30425ba88
add function of changing scales (joystick right / left)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
funa0825 3:b1115b34e95b 1
funa0825 3:b1115b34e95b 2
funa0825 3:b1115b34e95b 3 #define mC 261.626
funa0825 3:b1115b34e95b 4 #define mD 293.665
funa0825 3:b1115b34e95b 5 #define mE 329.628
funa0825 3:b1115b34e95b 6 #define mF 349.228
funa0825 3:b1115b34e95b 7 #define mG 391.995
funa0825 3:b1115b34e95b 8 #define mA 440.000
funa0825 3:b1115b34e95b 9 #define mB 493.883
funa0825 3:b1115b34e95b 10 #define THRESH 80
max_0630 5:04b0c694b5a1 11 #define COUNT_MAX 15
toyohara 6:82aa8f2c3c47 12 #define DIM 3
toyohara 15:46ca600425fc 13 #define NUM_OF_NOTES 21
toyohara 15:46ca600425fc 14 #define NUM_OF_SCALE 2
toyohara 15:46ca600425fc 15
funa0825 3:b1115b34e95b 16 #include "C12832.h"
chris 0:f86c572491c3 17 #include "mbed.h"
funa0825 3:b1115b34e95b 18 #include "rtos.h"
toyohara 6:82aa8f2c3c47 19 #include "MMA7660.h"
toyohara 10:5fb0cef92e1b 20 #include "USBHostMSD.h"
toyohara 10:5fb0cef92e1b 21 #include "wave_player.h"
chris 0:f86c572491c3 22
funa0825 3:b1115b34e95b 23 C12832 lcd(p5, p7, p6, p8, p11);
chris 1:0a08d26b011a 24 DigitalIn fire(p14);
funa0825 3:b1115b34e95b 25 //DigitalIn up(p15);
funa0825 3:b1115b34e95b 26 //DigitalIn down(p12);
funa0825 3:b1115b34e95b 27 PwmOut sp1(p26);
funa0825 3:b1115b34e95b 28 InterruptIn myup(p15);
funa0825 3:b1115b34e95b 29 InterruptIn mydown(p12);
funa0825 3:b1115b34e95b 30 PwmOut led1(p23);
funa0825 3:b1115b34e95b 31 PwmOut led2(p24);
funa0825 3:b1115b34e95b 32 PwmOut led3(p25);
funa0825 3:b1115b34e95b 33 Semaphore three_slots(1);
funa0825 3:b1115b34e95b 34 Timer for_chat;
toyohara 15:46ca600425fc 35
chris 0:f86c572491c3 36
toyohara 6:82aa8f2c3c47 37 //for acceleration sonsor
toyohara 6:82aa8f2c3c47 38 MMA7660 acc(p28, p27);
toyohara 6:82aa8f2c3c47 39 float r[DIM];
toyohara 6:82aa8f2c3c47 40
toyohara 10:5fb0cef92e1b 41 //for music
toyohara 10:5fb0cef92e1b 42 AnalogOut DACout (p18);
toyohara 12:c1148331b151 43 wave_player waver(&DACout);
toyohara 15:46ca600425fc 44 AnalogIn volumeMeter(p19);
toyohara 15:46ca600425fc 45 AnalogIn musicSwitch(p20);
toyohara 15:46ca600425fc 46 InterruptIn push(p14);
toyohara 15:46ca600425fc 47 InterruptIn right(p16);
toyohara 15:46ca600425fc 48 InterruptIn left(p13);
toyohara 10:5fb0cef92e1b 49
funa0825 3:b1115b34e95b 50 int i=0;
max_0630 5:04b0c694b5a1 51 int count = 0;
toyohara 15:46ca600425fc 52 bool pushed = false;
toyohara 15:46ca600425fc 53 int i_for20mm;
toyohara 15:46ca600425fc 54 int i_for20mm_old = 0;
toyohara 15:46ca600425fc 55 int scale = 0;
max_0630 5:04b0c694b5a1 56
funa0825 3:b1115b34e95b 57 float mm[]={mC,mD,mE,mF,mG,mA,mB,mC*2,mD*2,mE*2,mF*2,mG*2,mA*2,mB*2,mC*4};
max_0630 14:3b123bcdd79c 58
toyohara 15:46ca600425fc 59 float mmm[]={mC,mD,mE,mF,mG,mA,mB,mC*2,mD*2,mE*2,mF*2,mG*2,mA*2,mB*2,mC*4, mD*4,mE*4,mF*4,mG*4,mA*4,mB*4};//has 21
toyohara 15:46ca600425fc 60 float notes[NUM_OF_SCALE][NUM_OF_NOTES] = { {mC,mD,mE,mF,mG,mA,mB,mC*2,mD*2,mE*2,mF*2,mG*2,mA*2,mB*2,mC*4, mD*4,mE*4,mF*4,mG*4,mA*4,mB*4},
toyohara 15:46ca600425fc 61 {mC,mC,mC,mC,mC,mC,mC,mC,mC,mC,mF*2,mG*2,mA*2,mB*2,mC*4, mD*4,mE*4,mF*4,mG*4,mA*4,mB*4}};
funa0825 3:b1115b34e95b 62 void intRise(void)
funa0825 3:b1115b34e95b 63 {
funa0825 3:b1115b34e95b 64 if(for_chat.read_ms()>THRESH);
funa0825 3:b1115b34e95b 65 {
max_0630 5:04b0c694b5a1 66 if(i<=13){
funa0825 3:b1115b34e95b 67 i++;
max_0630 5:04b0c694b5a1 68 count ++;
max_0630 5:04b0c694b5a1 69 }
funa0825 3:b1115b34e95b 70 sp1.period(1.0/mm[i]);
funa0825 3:b1115b34e95b 71 sp1.write(0.5f);
funa0825 3:b1115b34e95b 72 for_chat.reset();
funa0825 3:b1115b34e95b 73 }
funa0825 3:b1115b34e95b 74 }
funa0825 3:b1115b34e95b 75
funa0825 3:b1115b34e95b 76 void intFall(void)
funa0825 3:b1115b34e95b 77 {
funa0825 3:b1115b34e95b 78 if(for_chat.read_ms()>THRESH);
funa0825 3:b1115b34e95b 79 {
max_0630 5:04b0c694b5a1 80 if(i >=1){
funa0825 3:b1115b34e95b 81 i--;
max_0630 5:04b0c694b5a1 82 count --;
max_0630 5:04b0c694b5a1 83 }
funa0825 3:b1115b34e95b 84 sp1.period(1.0/mm[i]);
funa0825 3:b1115b34e95b 85 sp1.write(0.5f);
funa0825 3:b1115b34e95b 86 for_chat.reset();
funa0825 3:b1115b34e95b 87 }
funa0825 3:b1115b34e95b 88 }
funa0825 3:b1115b34e95b 89
toyohara 15:46ca600425fc 90 void On(void)
toyohara 15:46ca600425fc 91 {
toyohara 15:46ca600425fc 92 pushed = true;
toyohara 15:46ca600425fc 93 }
toyohara 15:46ca600425fc 94
toyohara 15:46ca600425fc 95 void Off(void)
toyohara 15:46ca600425fc 96 {
toyohara 15:46ca600425fc 97 pushed = false;
toyohara 15:46ca600425fc 98 }
toyohara 15:46ca600425fc 99
toyohara 15:46ca600425fc 100 void scaleUp(void)
toyohara 15:46ca600425fc 101 {
toyohara 15:46ca600425fc 102 if(for_chat.read_ms()>THRESH) ;
toyohara 15:46ca600425fc 103 {
toyohara 15:46ca600425fc 104 if (scale == NUM_OF_SCALE - 1)
toyohara 15:46ca600425fc 105 {
toyohara 15:46ca600425fc 106 scale = 0;
toyohara 15:46ca600425fc 107 } else
toyohara 15:46ca600425fc 108 {
toyohara 15:46ca600425fc 109 scale++;
toyohara 15:46ca600425fc 110 }
toyohara 15:46ca600425fc 111 //lcd.locate(10,10);
toyohara 15:46ca600425fc 112 //lcd.printf("scale %d", scale);
toyohara 15:46ca600425fc 113 }
toyohara 15:46ca600425fc 114 for_chat.reset();
toyohara 15:46ca600425fc 115 }
toyohara 15:46ca600425fc 116
toyohara 15:46ca600425fc 117 void scaleDown(void)
toyohara 15:46ca600425fc 118 {
toyohara 15:46ca600425fc 119 if(for_chat.read_ms()>THRESH) ;
toyohara 15:46ca600425fc 120 {
toyohara 15:46ca600425fc 121 if (scale == 0)
toyohara 15:46ca600425fc 122 {
toyohara 15:46ca600425fc 123 scale = NUM_OF_SCALE - 1;
toyohara 15:46ca600425fc 124 } else
toyohara 15:46ca600425fc 125 {
toyohara 15:46ca600425fc 126 scale--;
toyohara 15:46ca600425fc 127 }
toyohara 15:46ca600425fc 128 //lcd.locate(10,10);
toyohara 15:46ca600425fc 129 //lcd.printf("scale %d", scale);
toyohara 15:46ca600425fc 130 }
toyohara 15:46ca600425fc 131 for_chat.reset();
toyohara 15:46ca600425fc 132 }
toyohara 15:46ca600425fc 133
funa0825 3:b1115b34e95b 134
funa0825 3:b1115b34e95b 135 void r_thread(void const *argument)
funa0825 3:b1115b34e95b 136 {
funa0825 3:b1115b34e95b 137 float r = 0;
funa0825 3:b1115b34e95b 138 while (true)
funa0825 3:b1115b34e95b 139 {
funa0825 3:b1115b34e95b 140 r=0;
funa0825 3:b1115b34e95b 141 while(r<=1)
funa0825 3:b1115b34e95b 142 {
funa0825 3:b1115b34e95b 143 three_slots.wait();
max_0630 5:04b0c694b5a1 144 switch(count){
max_0630 5:04b0c694b5a1 145 case 0:r = 0.0;break;
max_0630 5:04b0c694b5a1 146 case 1:r=0.07;break;
max_0630 5:04b0c694b5a1 147 case 2:r=0.13;break;
max_0630 5:04b0c694b5a1 148 case 3:r=0.20;break;
max_0630 5:04b0c694b5a1 149 case 4:r=0.27;break;
max_0630 5:04b0c694b5a1 150 case 5:r=0.34;break;
max_0630 5:04b0c694b5a1 151 case 6:r=0.41;break;
max_0630 5:04b0c694b5a1 152 case 7:r=0.48;break;
max_0630 5:04b0c694b5a1 153 case 8:r=0.55;break;
max_0630 5:04b0c694b5a1 154 case 9:r=0.62;break;
max_0630 5:04b0c694b5a1 155 case 10:r=0.69;break;
max_0630 5:04b0c694b5a1 156 case 11:r=0.76;break;
max_0630 5:04b0c694b5a1 157 case 12:r=0.83;break;
max_0630 5:04b0c694b5a1 158 case 13:r=0.90;break;
max_0630 5:04b0c694b5a1 159 case 14:r=0.97;break;
max_0630 5:04b0c694b5a1 160 }
max_0630 5:04b0c694b5a1 161 //r = (float)(count%COUNT_MAX)/COUNT_MAX;
funa0825 3:b1115b34e95b 162 led1 = r;
max_0630 5:04b0c694b5a1 163 //r += 0.01;
funa0825 3:b1115b34e95b 164 lcd.locate(0,16);
funa0825 3:b1115b34e95b 165 lcd.printf("R: %3.2f",r);
funa0825 3:b1115b34e95b 166 three_slots.release();
funa0825 3:b1115b34e95b 167 Thread::wait(100);
funa0825 3:b1115b34e95b 168
funa0825 3:b1115b34e95b 169 }
funa0825 3:b1115b34e95b 170 while(r>0)
funa0825 3:b1115b34e95b 171 {
funa0825 3:b1115b34e95b 172 three_slots.wait();
max_0630 5:04b0c694b5a1 173 switch(count){
max_0630 5:04b0c694b5a1 174 case 0:r = 0.0;break;
max_0630 5:04b0c694b5a1 175 case 1:r=0.07;break;
max_0630 5:04b0c694b5a1 176 case 2:r=0.13;break;
max_0630 5:04b0c694b5a1 177 case 3:r=0.20;break;
max_0630 5:04b0c694b5a1 178 case 4:r=0.27;break;
max_0630 5:04b0c694b5a1 179 case 5:r=0.34;break;
max_0630 5:04b0c694b5a1 180 case 6:r=0.41;break;
max_0630 5:04b0c694b5a1 181 case 7:r=0.48;break;
max_0630 5:04b0c694b5a1 182 case 8:r=0.55;break;
max_0630 5:04b0c694b5a1 183 case 9:r=0.62;break;
max_0630 5:04b0c694b5a1 184 case 10:r=0.69;break;
max_0630 5:04b0c694b5a1 185 case 11:r=0.76;break;
max_0630 5:04b0c694b5a1 186 case 12:r=0.83;break;
max_0630 5:04b0c694b5a1 187 case 13:r=0.90;break;
max_0630 5:04b0c694b5a1 188 case 14:r=0.97;break;
max_0630 5:04b0c694b5a1 189 }
max_0630 5:04b0c694b5a1 190 //r = (float)(count%COUNT_MAX)/COUNT_MAX;
funa0825 3:b1115b34e95b 191 led1 = r;
max_0630 5:04b0c694b5a1 192 //r -= 0.01;
funa0825 3:b1115b34e95b 193 lcd.locate(0,16);
funa0825 3:b1115b34e95b 194 lcd.printf("R: %3.2f",r);
funa0825 3:b1115b34e95b 195 three_slots.release();
funa0825 3:b1115b34e95b 196 Thread::wait(100);
funa0825 3:b1115b34e95b 197
funa0825 3:b1115b34e95b 198 }
funa0825 3:b1115b34e95b 199 }
funa0825 3:b1115b34e95b 200 }
funa0825 3:b1115b34e95b 201 void g_thread(void const *argument)
chris 0:f86c572491c3 202 {
funa0825 3:b1115b34e95b 203 float g = 0;
funa0825 3:b1115b34e95b 204 while (true)
funa0825 3:b1115b34e95b 205 {
funa0825 3:b1115b34e95b 206 g=0;
funa0825 3:b1115b34e95b 207 while(g<=1)
funa0825 3:b1115b34e95b 208 {
funa0825 3:b1115b34e95b 209 three_slots.wait();
max_0630 5:04b0c694b5a1 210 switch(count){
max_0630 5:04b0c694b5a1 211 case 0:g = 0.50;break;
max_0630 5:04b0c694b5a1 212 case 1:g = 0.50;break;
max_0630 5:04b0c694b5a1 213 case 2:g=0.63;break;
max_0630 5:04b0c694b5a1 214 case 3:g=0.63;break;
max_0630 5:04b0c694b5a1 215 case 4:g=0.77;break;
max_0630 5:04b0c694b5a1 216 case 5:g=0.77;break;
max_0630 5:04b0c694b5a1 217 case 6:g=0.90;break;
max_0630 5:04b0c694b5a1 218 case 7:g=0.90;break;
max_0630 5:04b0c694b5a1 219 case 8:g=0.47;break;
max_0630 5:04b0c694b5a1 220 case 9:g=0.47;break;
max_0630 5:04b0c694b5a1 221 case 10:g=0.33;break;
max_0630 5:04b0c694b5a1 222 case 11:g=0.33;break;
max_0630 5:04b0c694b5a1 223 case 12:g=0.20;break;
max_0630 5:04b0c694b5a1 224 case 13:g=0.20;break;
max_0630 5:04b0c694b5a1 225 case 14:g=0.07;break;
max_0630 5:04b0c694b5a1 226 }
funa0825 3:b1115b34e95b 227 led2 = g;
max_0630 5:04b0c694b5a1 228 //g += 0.01;
funa0825 3:b1115b34e95b 229 lcd.locate(40,16);
funa0825 3:b1115b34e95b 230 lcd.printf("G: %3.2f",g);
funa0825 3:b1115b34e95b 231 three_slots.release();
funa0825 3:b1115b34e95b 232 Thread::wait(200);
funa0825 3:b1115b34e95b 233 }
funa0825 3:b1115b34e95b 234 while(g>0)
funa0825 3:b1115b34e95b 235 {
funa0825 3:b1115b34e95b 236 three_slots.wait();
max_0630 5:04b0c694b5a1 237 switch(count){
max_0630 5:04b0c694b5a1 238 case 0:g = 0.50;break;
max_0630 5:04b0c694b5a1 239 case 1:g = 0.50;break;
max_0630 5:04b0c694b5a1 240 case 2:g=0.63;break;
max_0630 5:04b0c694b5a1 241 case 3:g=0.63;break;
max_0630 5:04b0c694b5a1 242 case 4:g=0.77;break;
max_0630 5:04b0c694b5a1 243 case 5:g=0.77;break;
max_0630 5:04b0c694b5a1 244 case 6:g=0.90;break;
max_0630 5:04b0c694b5a1 245 case 7:g=0.90;break;
max_0630 5:04b0c694b5a1 246 case 8:g=0.47;break;
max_0630 5:04b0c694b5a1 247 case 9:g=0.47;break;
max_0630 5:04b0c694b5a1 248 case 10:g=0.33;break;
max_0630 5:04b0c694b5a1 249 case 11:g=0.33;break;
max_0630 5:04b0c694b5a1 250 case 12:g=0.20;break;
max_0630 5:04b0c694b5a1 251 case 13:g=0.20;break;
max_0630 5:04b0c694b5a1 252 case 14:g=0.07;break;
max_0630 5:04b0c694b5a1 253 }
funa0825 3:b1115b34e95b 254 led2 = g;
max_0630 5:04b0c694b5a1 255 //g -= 0.01;
funa0825 3:b1115b34e95b 256 lcd.locate(40,16);
funa0825 3:b1115b34e95b 257 lcd.printf("G: %3.2f",g);
funa0825 3:b1115b34e95b 258 three_slots.release();
funa0825 3:b1115b34e95b 259 Thread::wait(200);
funa0825 3:b1115b34e95b 260 }
funa0825 3:b1115b34e95b 261 }
funa0825 3:b1115b34e95b 262 }
funa0825 3:b1115b34e95b 263 void b_thread(void const *argument)
funa0825 3:b1115b34e95b 264 {
funa0825 3:b1115b34e95b 265 float b = 0;
funa0825 3:b1115b34e95b 266 while (true)
funa0825 3:b1115b34e95b 267 {
funa0825 3:b1115b34e95b 268 b=0;
funa0825 3:b1115b34e95b 269 while(b<=1)
funa0825 3:b1115b34e95b 270 {
funa0825 3:b1115b34e95b 271 three_slots.wait();
max_0630 5:04b0c694b5a1 272 switch(count){
max_0630 5:04b0c694b5a1 273 case 0:b = 1.00;break;
max_0630 5:04b0c694b5a1 274 case 1:b = 1.00;break;
max_0630 5:04b0c694b5a1 275 case 2:b=1.00;break;
max_0630 5:04b0c694b5a1 276 case 3:b=0.80;break;
max_0630 5:04b0c694b5a1 277 case 4:b=0.80;break;
max_0630 5:04b0c694b5a1 278 case 5:b=0.80;break;
max_0630 5:04b0c694b5a1 279 case 6:b=0.60;break;
max_0630 5:04b0c694b5a1 280 case 7:b=0.60;break;
max_0630 5:04b0c694b5a1 281 case 8:b=0.60;break;
max_0630 5:04b0c694b5a1 282 case 9:b=0.40;break;
max_0630 5:04b0c694b5a1 283 case 10:b=0.40;break;
max_0630 5:04b0c694b5a1 284 case 11:b=0.40;break;
max_0630 5:04b0c694b5a1 285 case 12:b=0.20;break;
max_0630 5:04b0c694b5a1 286 case 13:b=0.20;break;
max_0630 5:04b0c694b5a1 287 case 14:b=0.20;break;
max_0630 5:04b0c694b5a1 288 }
funa0825 3:b1115b34e95b 289 led3 = b;
max_0630 5:04b0c694b5a1 290 //b += 0.01;
funa0825 3:b1115b34e95b 291 lcd.locate(80,16);
funa0825 3:b1115b34e95b 292 lcd.printf("B: %3.2f",b);
funa0825 3:b1115b34e95b 293 three_slots.release();
funa0825 3:b1115b34e95b 294 Thread::wait(300);
chris 2:cfd337edff08 295 }
funa0825 3:b1115b34e95b 296 while(b>0)
funa0825 3:b1115b34e95b 297 {
funa0825 3:b1115b34e95b 298 three_slots.wait();
max_0630 5:04b0c694b5a1 299 switch(count){
max_0630 5:04b0c694b5a1 300 case 0:b = 1.00;break;
max_0630 5:04b0c694b5a1 301 case 1:b = 1.00;break;
max_0630 5:04b0c694b5a1 302 case 2:b=1.00;break;
max_0630 5:04b0c694b5a1 303 case 3:b=0.80;break;
max_0630 5:04b0c694b5a1 304 case 4:b=0.80;break;
max_0630 5:04b0c694b5a1 305 case 5:b=0.80;break;
max_0630 5:04b0c694b5a1 306 case 6:b=0.60;break;
max_0630 5:04b0c694b5a1 307 case 7:b=0.60;break;
max_0630 5:04b0c694b5a1 308 case 8:b=0.60;break;
max_0630 5:04b0c694b5a1 309 case 9:b=0.40;break;
max_0630 5:04b0c694b5a1 310 case 10:b=0.40;break;
max_0630 5:04b0c694b5a1 311 case 11:b=0.40;break;
max_0630 5:04b0c694b5a1 312 case 12:b=0.20;break;
max_0630 5:04b0c694b5a1 313 case 13:b=0.20;break;
max_0630 5:04b0c694b5a1 314 case 14:b=0.20;break;
max_0630 5:04b0c694b5a1 315 }
funa0825 3:b1115b34e95b 316 led3 = b;
max_0630 5:04b0c694b5a1 317 //b -= 0.01;
funa0825 3:b1115b34e95b 318 lcd.locate(80,16);
funa0825 3:b1115b34e95b 319 lcd.printf("B: %3.2f",b);
funa0825 3:b1115b34e95b 320 three_slots.release();
funa0825 3:b1115b34e95b 321 Thread::wait(300);
funa0825 3:b1115b34e95b 322 }
funa0825 3:b1115b34e95b 323 }
funa0825 3:b1115b34e95b 324 }
funa0825 3:b1115b34e95b 325 void count_thread(void const *argument)
funa0825 3:b1115b34e95b 326 {
funa0825 3:b1115b34e95b 327 while (true)
funa0825 3:b1115b34e95b 328 {
funa0825 3:b1115b34e95b 329 three_slots.wait();
funa0825 3:b1115b34e95b 330 lcd.locate(0,3);
max_0630 5:04b0c694b5a1 331 lcd.printf("Counting : %d ",i);
funa0825 3:b1115b34e95b 332 three_slots.release();
funa0825 3:b1115b34e95b 333 Thread::wait(100);
chris 0:f86c572491c3 334 }
funa0825 3:b1115b34e95b 335 }
toyohara 6:82aa8f2c3c47 336
toyohara 6:82aa8f2c3c47 337 void acc_thread(void const *argument)
toyohara 6:82aa8f2c3c47 338 {
toyohara 6:82aa8f2c3c47 339 while (true)
toyohara 6:82aa8f2c3c47 340 {
toyohara 6:82aa8f2c3c47 341 acc.readData(r);
toyohara 6:82aa8f2c3c47 342 lcd.locate(0,0);
toyohara 6:82aa8f2c3c47 343 lcd.printf("x = %f", r[0]);
toyohara 6:82aa8f2c3c47 344 lcd.locate(0,10);
toyohara 6:82aa8f2c3c47 345 lcd.printf("y = %f", r[1]);
toyohara 6:82aa8f2c3c47 346 lcd.locate(0,20);
toyohara 6:82aa8f2c3c47 347 lcd.printf("z = %f", r[2]);
toyohara 6:82aa8f2c3c47 348 Thread::wait(10);
toyohara 6:82aa8f2c3c47 349 }
toyohara 6:82aa8f2c3c47 350 }
toyohara 6:82aa8f2c3c47 351
max_0630 11:5e85ab7d4176 352 void disp_thread(void const *argument)
max_0630 11:5e85ab7d4176 353 {
toyohara 15:46ca600425fc 354 float volume;
toyohara 15:46ca600425fc 355 float mswitch;
toyohara 15:46ca600425fc 356
max_0630 11:5e85ab7d4176 357 while (true)
max_0630 11:5e85ab7d4176 358 {
toyohara 15:46ca600425fc 359 volume = volumeMeter.read();
toyohara 15:46ca600425fc 360 mswitch = musicSwitch.read();
toyohara 15:46ca600425fc 361 i_for20mm = (int)(mswitch*20);//change 20 param
max_0630 11:5e85ab7d4176 362 //wait(mpmeter);
toyohara 13:58877e942d84 363 //lcd.locate(0,10);
toyohara 13:58877e942d84 364 //lcd.printf("mpmeter = %f", mpmeter);
max_0630 14:3b123bcdd79c 365
max_0630 14:3b123bcdd79c 366 // for debug
max_0630 14:3b123bcdd79c 367 //lcd.locate(0,10);
max_0630 14:3b123bcdd79c 368 //lcd.printf("i = %d ", i_for20mm);
max_0630 14:3b123bcdd79c 369
toyohara 15:46ca600425fc 370 if (i_for20mm != i_for20mm_old)
toyohara 15:46ca600425fc 371 {
toyohara 15:46ca600425fc 372 sp1.period(1.0/(notes[scale][i_for20mm]));
toyohara 15:46ca600425fc 373 }
toyohara 15:46ca600425fc 374 i_for20mm_old = i_for20mm;
toyohara 15:46ca600425fc 375
toyohara 15:46ca600425fc 376 if(pushed)
toyohara 15:46ca600425fc 377 {
toyohara 15:46ca600425fc 378 sp1.write(volume);
toyohara 15:46ca600425fc 379 }
toyohara 15:46ca600425fc 380 else
toyohara 15:46ca600425fc 381 {
toyohara 15:46ca600425fc 382 sp1.write(0.0f);
toyohara 15:46ca600425fc 383 }
toyohara 15:46ca600425fc 384
toyohara 15:46ca600425fc 385 for_chat.reset();
max_0630 14:3b123bcdd79c 386 /////////////////////////////
toyohara 15:46ca600425fc 387
toyohara 15:46ca600425fc 388 //for debug
toyohara 15:46ca600425fc 389 //lcd.locate(0,0);
toyohara 15:46ca600425fc 390 //lcd.printf("volume = %f", volume);
max_0630 11:5e85ab7d4176 391 //wait(mpmeter);
toyohara 15:46ca600425fc 392 Thread::wait(50);
max_0630 11:5e85ab7d4176 393 }
max_0630 11:5e85ab7d4176 394 }
max_0630 11:5e85ab7d4176 395
toyohara 12:c1148331b151 396
funa0825 3:b1115b34e95b 397 int main()
funa0825 3:b1115b34e95b 398 {
funa0825 3:b1115b34e95b 399 wait(0.01);
funa0825 3:b1115b34e95b 400 for_chat.start();
funa0825 3:b1115b34e95b 401 myup.fall(&intRise);
funa0825 3:b1115b34e95b 402 mydown.fall(&intFall);
toyohara 15:46ca600425fc 403 push.rise(&On);
toyohara 15:46ca600425fc 404 push.fall(&Off);
toyohara 15:46ca600425fc 405 right.rise(&scaleUp);
toyohara 15:46ca600425fc 406 left.rise(&scaleDown);
toyohara 15:46ca600425fc 407
toyohara 15:46ca600425fc 408
toyohara 6:82aa8f2c3c47 409 //Thread thread1(r_thread,(void *)"Th 1");
toyohara 6:82aa8f2c3c47 410 //Thread thread2(g_thread,(void *)"Th 2");
toyohara 6:82aa8f2c3c47 411 //Thread thread3(b_thread,(void *)"Th 3");
toyohara 6:82aa8f2c3c47 412 //Thread thread4(count_thread,(void *)"Th 4");
max_0630 11:5e85ab7d4176 413 //Thread thread5(acc_thread,(void *)"Th 5");
max_0630 11:5e85ab7d4176 414 Thread thread6(disp_thread, (void *)"Th 6");
toyohara 12:c1148331b151 415 //Thread thread7(sound_thread, (void *)"Th 7");
toyohara 12:c1148331b151 416
toyohara 10:5fb0cef92e1b 417 //for USB
toyohara 10:5fb0cef92e1b 418 USBHostMSD msd("usb");
toyohara 10:5fb0cef92e1b 419 while(!msd.connect())
toyohara 10:5fb0cef92e1b 420 {
toyohara 10:5fb0cef92e1b 421 Thread::wait(200);
toyohara 10:5fb0cef92e1b 422 }
toyohara 10:5fb0cef92e1b 423
toyohara 10:5fb0cef92e1b 424 //for music file
toyohara 10:5fb0cef92e1b 425 FILE *wave_file;
toyohara 12:c1148331b151 426 //sp1.period(1.0 / 16000.0);
toyohara 15:46ca600425fc 427 wave_file = fopen("/usb/music/BGMforMBED2.wav", "r");
toyohara 10:5fb0cef92e1b 428 waver.play(wave_file);
toyohara 10:5fb0cef92e1b 429 fclose(wave_file);
toyohara 10:5fb0cef92e1b 430
funa0825 3:b1115b34e95b 431 lcd.cls();
funa0825 3:b1115b34e95b 432 wait(0.01);
funa0825 3:b1115b34e95b 433 while(1)
funa0825 3:b1115b34e95b 434 {
funa0825 3:b1115b34e95b 435 //lcd.cls();
funa0825 3:b1115b34e95b 436
funa0825 3:b1115b34e95b 437 }
funa0825 3:b1115b34e95b 438 }
funa0825 3:b1115b34e95b 439