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