テスト

Dependencies:   C12832 USBHost mbed MMA7660 wave_player

Fork of app-board-Speaker by Ryohei Funakoshi

Committer:
toyohara
Date:
Sun Dec 11 05:47:29 2016 +0000
Revision:
8:230638bf12cb
Parent:
7:23f7e3ac3a8b
Child:
10:5fb0cef92e1b
a

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