テスト

Dependencies:   C12832 USBHost mbed MMA7660 wave_player

Fork of app-board-Speaker by Ryohei Funakoshi

Committer:
toyohara
Date:
Sun Dec 11 04:53:31 2016 +0000
Revision:
6:82aa8f2c3c47
Parent:
5:04b0c694b5a1
Child:
7:23f7e3ac3a8b
????????

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
funa0825 3:b1115b34e95b 13 #include "C12832.h"
chris 0:f86c572491c3 14 #include "mbed.h"
funa0825 3:b1115b34e95b 15 #include "rtos.h"
toyohara 6:82aa8f2c3c47 16 #include "MMA7660.h"
chris 0:f86c572491c3 17
funa0825 3:b1115b34e95b 18 C12832 lcd(p5, p7, p6, p8, p11);
chris 1:0a08d26b011a 19 DigitalIn fire(p14);
funa0825 3:b1115b34e95b 20 //DigitalIn up(p15);
funa0825 3:b1115b34e95b 21 //DigitalIn down(p12);
funa0825 3:b1115b34e95b 22 PwmOut sp1(p26);
funa0825 3:b1115b34e95b 23 InterruptIn myup(p15);
funa0825 3:b1115b34e95b 24 InterruptIn mydown(p12);
funa0825 3:b1115b34e95b 25 PwmOut led1(p23);
funa0825 3:b1115b34e95b 26 PwmOut led2(p24);
funa0825 3:b1115b34e95b 27 PwmOut led3(p25);
funa0825 3:b1115b34e95b 28 Semaphore three_slots(1);
funa0825 3:b1115b34e95b 29 Timer for_chat;
chris 0:f86c572491c3 30
toyohara 6:82aa8f2c3c47 31 //for acceleration sonsor
toyohara 6:82aa8f2c3c47 32 MMA7660 acc(p28, p27);
toyohara 6:82aa8f2c3c47 33 float r[DIM];
toyohara 6:82aa8f2c3c47 34
funa0825 3:b1115b34e95b 35 int i=0;
max_0630 5:04b0c694b5a1 36 int count = 0;
max_0630 5:04b0c694b5a1 37
funa0825 3:b1115b34e95b 38 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};
funa0825 3:b1115b34e95b 39 void intRise(void)
funa0825 3:b1115b34e95b 40 {
funa0825 3:b1115b34e95b 41 if(for_chat.read_ms()>THRESH);
funa0825 3:b1115b34e95b 42 {
max_0630 5:04b0c694b5a1 43 if(i<=13){
funa0825 3:b1115b34e95b 44 i++;
max_0630 5:04b0c694b5a1 45 count ++;
max_0630 5:04b0c694b5a1 46 }
funa0825 3:b1115b34e95b 47 sp1.period(1.0/mm[i]);
funa0825 3:b1115b34e95b 48 sp1.write(0.5f);
funa0825 3:b1115b34e95b 49 for_chat.reset();
funa0825 3:b1115b34e95b 50 }
funa0825 3:b1115b34e95b 51 }
funa0825 3:b1115b34e95b 52
funa0825 3:b1115b34e95b 53 void intFall(void)
funa0825 3:b1115b34e95b 54 {
funa0825 3:b1115b34e95b 55 if(for_chat.read_ms()>THRESH);
funa0825 3:b1115b34e95b 56 {
max_0630 5:04b0c694b5a1 57 if(i >=1){
funa0825 3:b1115b34e95b 58 i--;
max_0630 5:04b0c694b5a1 59 count --;
max_0630 5:04b0c694b5a1 60 }
funa0825 3:b1115b34e95b 61 sp1.period(1.0/mm[i]);
funa0825 3:b1115b34e95b 62 sp1.write(0.5f);
funa0825 3:b1115b34e95b 63 for_chat.reset();
funa0825 3:b1115b34e95b 64 }
funa0825 3:b1115b34e95b 65 }
funa0825 3:b1115b34e95b 66
funa0825 3:b1115b34e95b 67
funa0825 3:b1115b34e95b 68 void r_thread(void const *argument)
funa0825 3:b1115b34e95b 69 {
funa0825 3:b1115b34e95b 70 float r = 0;
funa0825 3:b1115b34e95b 71 while (true)
funa0825 3:b1115b34e95b 72 {
funa0825 3:b1115b34e95b 73 r=0;
funa0825 3:b1115b34e95b 74 while(r<=1)
funa0825 3:b1115b34e95b 75 {
funa0825 3:b1115b34e95b 76 three_slots.wait();
max_0630 5:04b0c694b5a1 77 switch(count){
max_0630 5:04b0c694b5a1 78 case 0:r = 0.0;break;
max_0630 5:04b0c694b5a1 79 case 1:r=0.07;break;
max_0630 5:04b0c694b5a1 80 case 2:r=0.13;break;
max_0630 5:04b0c694b5a1 81 case 3:r=0.20;break;
max_0630 5:04b0c694b5a1 82 case 4:r=0.27;break;
max_0630 5:04b0c694b5a1 83 case 5:r=0.34;break;
max_0630 5:04b0c694b5a1 84 case 6:r=0.41;break;
max_0630 5:04b0c694b5a1 85 case 7:r=0.48;break;
max_0630 5:04b0c694b5a1 86 case 8:r=0.55;break;
max_0630 5:04b0c694b5a1 87 case 9:r=0.62;break;
max_0630 5:04b0c694b5a1 88 case 10:r=0.69;break;
max_0630 5:04b0c694b5a1 89 case 11:r=0.76;break;
max_0630 5:04b0c694b5a1 90 case 12:r=0.83;break;
max_0630 5:04b0c694b5a1 91 case 13:r=0.90;break;
max_0630 5:04b0c694b5a1 92 case 14:r=0.97;break;
max_0630 5:04b0c694b5a1 93 }
max_0630 5:04b0c694b5a1 94 //r = (float)(count%COUNT_MAX)/COUNT_MAX;
funa0825 3:b1115b34e95b 95 led1 = r;
max_0630 5:04b0c694b5a1 96 //r += 0.01;
funa0825 3:b1115b34e95b 97 lcd.locate(0,16);
funa0825 3:b1115b34e95b 98 lcd.printf("R: %3.2f",r);
funa0825 3:b1115b34e95b 99 three_slots.release();
funa0825 3:b1115b34e95b 100 Thread::wait(100);
funa0825 3:b1115b34e95b 101
funa0825 3:b1115b34e95b 102 }
funa0825 3:b1115b34e95b 103 while(r>0)
funa0825 3:b1115b34e95b 104 {
funa0825 3:b1115b34e95b 105 three_slots.wait();
max_0630 5:04b0c694b5a1 106 switch(count){
max_0630 5:04b0c694b5a1 107 case 0:r = 0.0;break;
max_0630 5:04b0c694b5a1 108 case 1:r=0.07;break;
max_0630 5:04b0c694b5a1 109 case 2:r=0.13;break;
max_0630 5:04b0c694b5a1 110 case 3:r=0.20;break;
max_0630 5:04b0c694b5a1 111 case 4:r=0.27;break;
max_0630 5:04b0c694b5a1 112 case 5:r=0.34;break;
max_0630 5:04b0c694b5a1 113 case 6:r=0.41;break;
max_0630 5:04b0c694b5a1 114 case 7:r=0.48;break;
max_0630 5:04b0c694b5a1 115 case 8:r=0.55;break;
max_0630 5:04b0c694b5a1 116 case 9:r=0.62;break;
max_0630 5:04b0c694b5a1 117 case 10:r=0.69;break;
max_0630 5:04b0c694b5a1 118 case 11:r=0.76;break;
max_0630 5:04b0c694b5a1 119 case 12:r=0.83;break;
max_0630 5:04b0c694b5a1 120 case 13:r=0.90;break;
max_0630 5:04b0c694b5a1 121 case 14:r=0.97;break;
max_0630 5:04b0c694b5a1 122 }
max_0630 5:04b0c694b5a1 123 //r = (float)(count%COUNT_MAX)/COUNT_MAX;
funa0825 3:b1115b34e95b 124 led1 = r;
max_0630 5:04b0c694b5a1 125 //r -= 0.01;
funa0825 3:b1115b34e95b 126 lcd.locate(0,16);
funa0825 3:b1115b34e95b 127 lcd.printf("R: %3.2f",r);
funa0825 3:b1115b34e95b 128 three_slots.release();
funa0825 3:b1115b34e95b 129 Thread::wait(100);
funa0825 3:b1115b34e95b 130
funa0825 3:b1115b34e95b 131 }
funa0825 3:b1115b34e95b 132 }
funa0825 3:b1115b34e95b 133 }
funa0825 3:b1115b34e95b 134 void g_thread(void const *argument)
chris 0:f86c572491c3 135 {
funa0825 3:b1115b34e95b 136 float g = 0;
funa0825 3:b1115b34e95b 137 while (true)
funa0825 3:b1115b34e95b 138 {
funa0825 3:b1115b34e95b 139 g=0;
funa0825 3:b1115b34e95b 140 while(g<=1)
funa0825 3:b1115b34e95b 141 {
funa0825 3:b1115b34e95b 142 three_slots.wait();
max_0630 5:04b0c694b5a1 143 switch(count){
max_0630 5:04b0c694b5a1 144 case 0:g = 0.50;break;
max_0630 5:04b0c694b5a1 145 case 1:g = 0.50;break;
max_0630 5:04b0c694b5a1 146 case 2:g=0.63;break;
max_0630 5:04b0c694b5a1 147 case 3:g=0.63;break;
max_0630 5:04b0c694b5a1 148 case 4:g=0.77;break;
max_0630 5:04b0c694b5a1 149 case 5:g=0.77;break;
max_0630 5:04b0c694b5a1 150 case 6:g=0.90;break;
max_0630 5:04b0c694b5a1 151 case 7:g=0.90;break;
max_0630 5:04b0c694b5a1 152 case 8:g=0.47;break;
max_0630 5:04b0c694b5a1 153 case 9:g=0.47;break;
max_0630 5:04b0c694b5a1 154 case 10:g=0.33;break;
max_0630 5:04b0c694b5a1 155 case 11:g=0.33;break;
max_0630 5:04b0c694b5a1 156 case 12:g=0.20;break;
max_0630 5:04b0c694b5a1 157 case 13:g=0.20;break;
max_0630 5:04b0c694b5a1 158 case 14:g=0.07;break;
max_0630 5:04b0c694b5a1 159 }
funa0825 3:b1115b34e95b 160 led2 = g;
max_0630 5:04b0c694b5a1 161 //g += 0.01;
funa0825 3:b1115b34e95b 162 lcd.locate(40,16);
funa0825 3:b1115b34e95b 163 lcd.printf("G: %3.2f",g);
funa0825 3:b1115b34e95b 164 three_slots.release();
funa0825 3:b1115b34e95b 165 Thread::wait(200);
funa0825 3:b1115b34e95b 166 }
funa0825 3:b1115b34e95b 167 while(g>0)
funa0825 3:b1115b34e95b 168 {
funa0825 3:b1115b34e95b 169 three_slots.wait();
max_0630 5:04b0c694b5a1 170 switch(count){
max_0630 5:04b0c694b5a1 171 case 0:g = 0.50;break;
max_0630 5:04b0c694b5a1 172 case 1:g = 0.50;break;
max_0630 5:04b0c694b5a1 173 case 2:g=0.63;break;
max_0630 5:04b0c694b5a1 174 case 3:g=0.63;break;
max_0630 5:04b0c694b5a1 175 case 4:g=0.77;break;
max_0630 5:04b0c694b5a1 176 case 5:g=0.77;break;
max_0630 5:04b0c694b5a1 177 case 6:g=0.90;break;
max_0630 5:04b0c694b5a1 178 case 7:g=0.90;break;
max_0630 5:04b0c694b5a1 179 case 8:g=0.47;break;
max_0630 5:04b0c694b5a1 180 case 9:g=0.47;break;
max_0630 5:04b0c694b5a1 181 case 10:g=0.33;break;
max_0630 5:04b0c694b5a1 182 case 11:g=0.33;break;
max_0630 5:04b0c694b5a1 183 case 12:g=0.20;break;
max_0630 5:04b0c694b5a1 184 case 13:g=0.20;break;
max_0630 5:04b0c694b5a1 185 case 14:g=0.07;break;
max_0630 5:04b0c694b5a1 186 }
funa0825 3:b1115b34e95b 187 led2 = g;
max_0630 5:04b0c694b5a1 188 //g -= 0.01;
funa0825 3:b1115b34e95b 189 lcd.locate(40,16);
funa0825 3:b1115b34e95b 190 lcd.printf("G: %3.2f",g);
funa0825 3:b1115b34e95b 191 three_slots.release();
funa0825 3:b1115b34e95b 192 Thread::wait(200);
funa0825 3:b1115b34e95b 193 }
funa0825 3:b1115b34e95b 194 }
funa0825 3:b1115b34e95b 195 }
funa0825 3:b1115b34e95b 196 void b_thread(void const *argument)
funa0825 3:b1115b34e95b 197 {
funa0825 3:b1115b34e95b 198 float b = 0;
funa0825 3:b1115b34e95b 199 while (true)
funa0825 3:b1115b34e95b 200 {
funa0825 3:b1115b34e95b 201 b=0;
funa0825 3:b1115b34e95b 202 while(b<=1)
funa0825 3:b1115b34e95b 203 {
funa0825 3:b1115b34e95b 204 three_slots.wait();
max_0630 5:04b0c694b5a1 205 switch(count){
max_0630 5:04b0c694b5a1 206 case 0:b = 1.00;break;
max_0630 5:04b0c694b5a1 207 case 1:b = 1.00;break;
max_0630 5:04b0c694b5a1 208 case 2:b=1.00;break;
max_0630 5:04b0c694b5a1 209 case 3:b=0.80;break;
max_0630 5:04b0c694b5a1 210 case 4:b=0.80;break;
max_0630 5:04b0c694b5a1 211 case 5:b=0.80;break;
max_0630 5:04b0c694b5a1 212 case 6:b=0.60;break;
max_0630 5:04b0c694b5a1 213 case 7:b=0.60;break;
max_0630 5:04b0c694b5a1 214 case 8:b=0.60;break;
max_0630 5:04b0c694b5a1 215 case 9:b=0.40;break;
max_0630 5:04b0c694b5a1 216 case 10:b=0.40;break;
max_0630 5:04b0c694b5a1 217 case 11:b=0.40;break;
max_0630 5:04b0c694b5a1 218 case 12:b=0.20;break;
max_0630 5:04b0c694b5a1 219 case 13:b=0.20;break;
max_0630 5:04b0c694b5a1 220 case 14:b=0.20;break;
max_0630 5:04b0c694b5a1 221 }
funa0825 3:b1115b34e95b 222 led3 = b;
max_0630 5:04b0c694b5a1 223 //b += 0.01;
funa0825 3:b1115b34e95b 224 lcd.locate(80,16);
funa0825 3:b1115b34e95b 225 lcd.printf("B: %3.2f",b);
funa0825 3:b1115b34e95b 226 three_slots.release();
funa0825 3:b1115b34e95b 227 Thread::wait(300);
chris 2:cfd337edff08 228 }
funa0825 3:b1115b34e95b 229 while(b>0)
funa0825 3:b1115b34e95b 230 {
funa0825 3:b1115b34e95b 231 three_slots.wait();
max_0630 5:04b0c694b5a1 232 switch(count){
max_0630 5:04b0c694b5a1 233 case 0:b = 1.00;break;
max_0630 5:04b0c694b5a1 234 case 1:b = 1.00;break;
max_0630 5:04b0c694b5a1 235 case 2:b=1.00;break;
max_0630 5:04b0c694b5a1 236 case 3:b=0.80;break;
max_0630 5:04b0c694b5a1 237 case 4:b=0.80;break;
max_0630 5:04b0c694b5a1 238 case 5:b=0.80;break;
max_0630 5:04b0c694b5a1 239 case 6:b=0.60;break;
max_0630 5:04b0c694b5a1 240 case 7:b=0.60;break;
max_0630 5:04b0c694b5a1 241 case 8:b=0.60;break;
max_0630 5:04b0c694b5a1 242 case 9:b=0.40;break;
max_0630 5:04b0c694b5a1 243 case 10:b=0.40;break;
max_0630 5:04b0c694b5a1 244 case 11:b=0.40;break;
max_0630 5:04b0c694b5a1 245 case 12:b=0.20;break;
max_0630 5:04b0c694b5a1 246 case 13:b=0.20;break;
max_0630 5:04b0c694b5a1 247 case 14:b=0.20;break;
max_0630 5:04b0c694b5a1 248 }
funa0825 3:b1115b34e95b 249 led3 = b;
max_0630 5:04b0c694b5a1 250 //b -= 0.01;
funa0825 3:b1115b34e95b 251 lcd.locate(80,16);
funa0825 3:b1115b34e95b 252 lcd.printf("B: %3.2f",b);
funa0825 3:b1115b34e95b 253 three_slots.release();
funa0825 3:b1115b34e95b 254 Thread::wait(300);
funa0825 3:b1115b34e95b 255 }
funa0825 3:b1115b34e95b 256 }
funa0825 3:b1115b34e95b 257 }
funa0825 3:b1115b34e95b 258 void count_thread(void const *argument)
funa0825 3:b1115b34e95b 259 {
funa0825 3:b1115b34e95b 260 while (true)
funa0825 3:b1115b34e95b 261 {
funa0825 3:b1115b34e95b 262 three_slots.wait();
funa0825 3:b1115b34e95b 263 lcd.locate(0,3);
max_0630 5:04b0c694b5a1 264 lcd.printf("Counting : %d ",i);
funa0825 3:b1115b34e95b 265 three_slots.release();
funa0825 3:b1115b34e95b 266 Thread::wait(100);
chris 0:f86c572491c3 267 }
funa0825 3:b1115b34e95b 268 }
toyohara 6:82aa8f2c3c47 269
toyohara 6:82aa8f2c3c47 270 void acc_thread(void const *argument)
toyohara 6:82aa8f2c3c47 271 {
toyohara 6:82aa8f2c3c47 272 while (true)
toyohara 6:82aa8f2c3c47 273 {
toyohara 6:82aa8f2c3c47 274 acc.readData(r);
toyohara 6:82aa8f2c3c47 275 lcd.locate(0,0);
toyohara 6:82aa8f2c3c47 276 lcd.printf("x = %f", r[0]);
toyohara 6:82aa8f2c3c47 277 lcd.locate(0,10);
toyohara 6:82aa8f2c3c47 278 lcd.printf("y = %f", r[1]);
toyohara 6:82aa8f2c3c47 279 lcd.locate(0,20);
toyohara 6:82aa8f2c3c47 280 lcd.printf("z = %f", r[2]);
toyohara 6:82aa8f2c3c47 281 Thread::wait(10);
toyohara 6:82aa8f2c3c47 282 }
toyohara 6:82aa8f2c3c47 283 }
toyohara 6:82aa8f2c3c47 284
funa0825 3:b1115b34e95b 285 int main()
funa0825 3:b1115b34e95b 286 {
funa0825 3:b1115b34e95b 287 wait(0.01);
funa0825 3:b1115b34e95b 288 for_chat.start();
funa0825 3:b1115b34e95b 289 myup.fall(&intRise);
funa0825 3:b1115b34e95b 290 mydown.fall(&intFall);
toyohara 6:82aa8f2c3c47 291 //Thread thread1(r_thread,(void *)"Th 1");
toyohara 6:82aa8f2c3c47 292 //Thread thread2(g_thread,(void *)"Th 2");
toyohara 6:82aa8f2c3c47 293 //Thread thread3(b_thread,(void *)"Th 3");
toyohara 6:82aa8f2c3c47 294 //Thread thread4(count_thread,(void *)"Th 4");
toyohara 6:82aa8f2c3c47 295 Thread thread5(acc_thread,(void *)"Th 5");
funa0825 3:b1115b34e95b 296
funa0825 3:b1115b34e95b 297 lcd.cls();
funa0825 3:b1115b34e95b 298 wait(0.01);
funa0825 3:b1115b34e95b 299 while(1)
funa0825 3:b1115b34e95b 300 {
funa0825 3:b1115b34e95b 301 //lcd.cls();
funa0825 3:b1115b34e95b 302
funa0825 3:b1115b34e95b 303 }
funa0825 3:b1115b34e95b 304 }
funa0825 3:b1115b34e95b 305