Saya Matsuura
/
drum_zenkoku
drum
main.cpp@1:52b83b268ebb, 2020-11-28 (annotated)
- Committer:
- 38
- Date:
- Sat Nov 28 15:35:41 2020 +0000
- Revision:
- 1:52b83b268ebb
- Parent:
- 0:cd5fcde85881
drum;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
38 | 0:cd5fcde85881 | 1 | #include <mbed.h> |
38 | 0:cd5fcde85881 | 2 | #include "astronomical_observation.h" |
38 | 0:cd5fcde85881 | 3 | #include "mugamutyu.h" |
38 | 0:cd5fcde85881 | 4 | #include "tapeled.h" |
38 | 0:cd5fcde85881 | 5 | #include "scrp_slave.hpp" |
38 | 0:cd5fcde85881 | 6 | |
38 | 0:cd5fcde85881 | 7 | ScrpSlave slave(PC_12, PD_2, PH_1, SERIAL_TX, SERIAL_RX, 0x0807f801); |
38 | 0:cd5fcde85881 | 8 | |
38 | 0:cd5fcde85881 | 9 | bool on_off; |
38 | 0:cd5fcde85881 | 10 | bool led; |
38 | 0:cd5fcde85881 | 11 | bool led_flag[12]; |
38 | 0:cd5fcde85881 | 12 | |
38 | 0:cd5fcde85881 | 13 | Timeout stop_0; |
38 | 0:cd5fcde85881 | 14 | Timeout stop_1; |
38 | 0:cd5fcde85881 | 15 | Timeout stop_2; |
38 | 0:cd5fcde85881 | 16 | Timeout stop_3; |
38 | 0:cd5fcde85881 | 17 | Timeout stop_4; |
38 | 0:cd5fcde85881 | 18 | Timeout stop_5; |
38 | 0:cd5fcde85881 | 19 | Timeout stop_6; |
38 | 0:cd5fcde85881 | 20 | Timeout stop_7; |
38 | 0:cd5fcde85881 | 21 | Timeout stop_8; |
38 | 0:cd5fcde85881 | 22 | Timeout stop_9;//drum_2_1 |
38 | 0:cd5fcde85881 | 23 | Timeout stop_10;//drum_5_1 |
38 | 0:cd5fcde85881 | 24 | Timeout stop_11;//cymbal_1_1 |
38 | 0:cd5fcde85881 | 25 | Timeout stop_12;//haihat_close |
38 | 0:cd5fcde85881 | 26 | Timeout stop_13;//haihat_middle |
38 | 0:cd5fcde85881 | 27 | |
38 | 0:cd5fcde85881 | 28 | Timeout drum_1_stop; |
38 | 0:cd5fcde85881 | 29 | |
38 | 0:cd5fcde85881 | 30 | |
38 | 0:cd5fcde85881 | 31 | Timer timekeeper; |
38 | 0:cd5fcde85881 | 32 | Timer timekeeper_1; |
38 | 0:cd5fcde85881 | 33 | |
38 | 0:cd5fcde85881 | 34 | Timer d1; |
38 | 0:cd5fcde85881 | 35 | |
38 | 0:cd5fcde85881 | 36 | void checkpoint(); |
38 | 0:cd5fcde85881 | 37 | void checkpoint1(); |
38 | 0:cd5fcde85881 | 38 | void checkpoint2(); |
38 | 0:cd5fcde85881 | 39 | void checkpoint1_2(); |
38 | 0:cd5fcde85881 | 40 | |
38 | 0:cd5fcde85881 | 41 | DigitalOut led_pin[4] = { |
38 | 0:cd5fcde85881 | 42 | DigitalOut(PA_10), |
38 | 0:cd5fcde85881 | 43 | DigitalOut(PB_15), |
38 | 0:cd5fcde85881 | 44 | DigitalOut(PB_2), |
38 | 0:cd5fcde85881 | 45 | DigitalOut(PC_6) |
38 | 0:cd5fcde85881 | 46 | }; |
38 | 0:cd5fcde85881 | 47 | |
38 | 0:cd5fcde85881 | 48 | DigitalOut solenoid[14] = { |
38 | 0:cd5fcde85881 | 49 | DigitalOut(PA_14),//バスドラム |
38 | 0:cd5fcde85881 | 50 | DigitalOut(PB_6),//スネアドラム_1 |
38 | 0:cd5fcde85881 | 51 | DigitalOut(PB_7),//スネアドラム_2 |
38 | 0:cd5fcde85881 | 52 | DigitalOut(PA_9),//ロータム |
38 | 0:cd5fcde85881 | 53 | DigitalOut(PA_1),//ハイタム |
38 | 0:cd5fcde85881 | 54 | DigitalOut(PC_3),//フロアタム_1 |
38 | 0:cd5fcde85881 | 55 | DigitalOut(PC_2),//フロアタム_2 |
38 | 0:cd5fcde85881 | 56 | DigitalOut(PB_4),//ハイハット_1 |
38 | 0:cd5fcde85881 | 57 | DigitalOut(PB_5),//ハイハット_2 |
38 | 0:cd5fcde85881 | 58 | DigitalOut(PA_0),//クラッシュシンバル_low |
38 | 0:cd5fcde85881 | 59 | DigitalOut(PC_0),//クラッシュシンバル_hight |
38 | 0:cd5fcde85881 | 60 | DigitalOut(PC_1),//ライドシンバル |
38 | 0:cd5fcde85881 | 61 | DigitalOut(PA_13),//ハイハットclosse |
38 | 0:cd5fcde85881 | 62 | DigitalOut(PC_4)//ハイハット//middle |
38 | 0:cd5fcde85881 | 63 | }; |
38 | 0:cd5fcde85881 | 64 | |
38 | 0:cd5fcde85881 | 65 | PwmOut motor_pin[1][2]= { |
38 | 0:cd5fcde85881 | 66 | {PwmOut(PA_11),PwmOut(PB_1)} |
38 | 0:cd5fcde85881 | 67 | }; |
38 | 0:cd5fcde85881 | 68 | |
38 | 0:cd5fcde85881 | 69 | InterruptIn limit_switch(PB_0,PullUp); |
38 | 0:cd5fcde85881 | 70 | |
38 | 0:cd5fcde85881 | 71 | void (*func[12])(); |
38 | 0:cd5fcde85881 | 72 | |
38 | 0:cd5fcde85881 | 73 | int status; |
38 | 0:cd5fcde85881 | 74 | int prev_status; |
38 | 0:cd5fcde85881 | 75 | |
38 | 0:cd5fcde85881 | 76 | |
38 | 0:cd5fcde85881 | 77 | bool pause(int rx_data, int &tx_data){ |
38 | 0:cd5fcde85881 | 78 | tx_data = rx_data; |
38 | 0:cd5fcde85881 | 79 | if(tx_data == 0){ |
38 | 0:cd5fcde85881 | 80 | status = 0; |
38 | 0:cd5fcde85881 | 81 | } |
38 | 0:cd5fcde85881 | 82 | return true; |
38 | 0:cd5fcde85881 | 83 | } |
38 | 0:cd5fcde85881 | 84 | |
38 | 0:cd5fcde85881 | 85 | bool setup(int rx_data, int &tx_data){ |
38 | 0:cd5fcde85881 | 86 | tx_data=rx_data; |
38 | 0:cd5fcde85881 | 87 | status=99; |
38 | 0:cd5fcde85881 | 88 | return true; |
38 | 0:cd5fcde85881 | 89 | } |
38 | 0:cd5fcde85881 | 90 | |
38 | 0:cd5fcde85881 | 91 | bool command0(int rx_data, int &tx_data ){ |
38 | 0:cd5fcde85881 | 92 | tx_data = rx_data; |
38 | 0:cd5fcde85881 | 93 | switch(tx_data){ |
38 | 0:cd5fcde85881 | 94 | case 1: |
38 | 0:cd5fcde85881 | 95 | status =1; |
38 | 0:cd5fcde85881 | 96 | break; |
38 | 0:cd5fcde85881 | 97 | case 2: |
38 | 0:cd5fcde85881 | 98 | status =2; |
38 | 0:cd5fcde85881 | 99 | break; |
38 | 0:cd5fcde85881 | 100 | case 3: |
38 | 0:cd5fcde85881 | 101 | status =3; |
38 | 0:cd5fcde85881 | 102 | break; |
38 | 0:cd5fcde85881 | 103 | |
38 | 0:cd5fcde85881 | 104 | //↓ 無我夢中 |
38 | 0:cd5fcde85881 | 105 | case 11: |
38 | 0:cd5fcde85881 | 106 | status =11; |
38 | 0:cd5fcde85881 | 107 | break; |
38 | 0:cd5fcde85881 | 108 | case 12: |
38 | 0:cd5fcde85881 | 109 | status =12; |
38 | 0:cd5fcde85881 | 110 | break; |
38 | 0:cd5fcde85881 | 111 | } |
38 | 0:cd5fcde85881 | 112 | return 1; |
38 | 0:cd5fcde85881 | 113 | } |
38 | 0:cd5fcde85881 | 114 | |
38 | 0:cd5fcde85881 | 115 | void drum(int num, bool on_off){ |
38 | 0:cd5fcde85881 | 116 | if(on_off == true){ |
38 | 0:cd5fcde85881 | 117 | timekeeper_1.start(); |
38 | 0:cd5fcde85881 | 118 | solenoid[num] = true; |
38 | 0:cd5fcde85881 | 119 | led_pin[num%4] = 1; |
38 | 0:cd5fcde85881 | 120 | }else if (on_off == false){ |
38 | 0:cd5fcde85881 | 121 | solenoid[num] = false; |
38 | 0:cd5fcde85881 | 122 | led_pin[num%4] = 0; |
38 | 0:cd5fcde85881 | 123 | } |
38 | 0:cd5fcde85881 | 124 | } |
38 | 0:cd5fcde85881 | 125 | |
38 | 0:cd5fcde85881 | 126 | void driveMotor(int num, double pwm){ |
38 | 0:cd5fcde85881 | 127 | if (!pwm) { |
38 | 0:cd5fcde85881 | 128 | motor_pin[num][0] = 0; |
38 | 0:cd5fcde85881 | 129 | motor_pin[num][1] = 0; |
38 | 0:cd5fcde85881 | 130 | led_pin[num%4] = 0; |
38 | 0:cd5fcde85881 | 131 | } else if (0 < pwm) { |
38 | 0:cd5fcde85881 | 132 | motor_pin[num][0] = pwm; |
38 | 0:cd5fcde85881 | 133 | motor_pin[num][1] = 0; |
38 | 0:cd5fcde85881 | 134 | led_pin[num%4] = 1; |
38 | 0:cd5fcde85881 | 135 | } else { |
38 | 0:cd5fcde85881 | 136 | motor_pin[num][0] = 0; |
38 | 0:cd5fcde85881 | 137 | motor_pin[num][1] = -pwm; |
38 | 0:cd5fcde85881 | 138 | led_pin[num%4] = 1; |
38 | 0:cd5fcde85881 | 139 | } |
38 | 0:cd5fcde85881 | 140 | } |
38 | 0:cd5fcde85881 | 141 | |
38 | 0:cd5fcde85881 | 142 | |
38 | 0:cd5fcde85881 | 143 | |
38 | 0:cd5fcde85881 | 144 | void stop0(){/* |
38 | 0:cd5fcde85881 | 145 | if(timekeeper_1.read_ms()>100){ |
38 | 0:cd5fcde85881 | 146 | stopt_0.attach_us(majistop1,100000); |
38 | 0:cd5fcde85881 | 147 | } |
38 | 0:cd5fcde85881 | 148 | if(d1.read_ms()>200) {*/ |
38 | 0:cd5fcde85881 | 149 | driveMotor(0,0); |
38 | 0:cd5fcde85881 | 150 | led_pin[0] = 0; |
38 | 0:cd5fcde85881 | 151 | //} |
38 | 0:cd5fcde85881 | 152 | } |
38 | 0:cd5fcde85881 | 153 | |
38 | 0:cd5fcde85881 | 154 | void stop1(){ |
38 | 0:cd5fcde85881 | 155 | drum(1,false); |
38 | 0:cd5fcde85881 | 156 | npx.off(); |
38 | 0:cd5fcde85881 | 157 | led_pin[1] = 0; |
38 | 0:cd5fcde85881 | 158 | } |
38 | 0:cd5fcde85881 | 159 | void stop2(){ |
38 | 0:cd5fcde85881 | 160 | drum(2,false); |
38 | 0:cd5fcde85881 | 161 | npx.off(); |
38 | 0:cd5fcde85881 | 162 | led_pin[2] = 0; |
38 | 0:cd5fcde85881 | 163 | } |
38 | 0:cd5fcde85881 | 164 | void stop3(){ |
38 | 0:cd5fcde85881 | 165 | drum(3,false); |
38 | 0:cd5fcde85881 | 166 | npx.off(); |
38 | 0:cd5fcde85881 | 167 | led_pin[3] = 0; |
38 | 0:cd5fcde85881 | 168 | } |
38 | 0:cd5fcde85881 | 169 | void stop4(){ |
38 | 0:cd5fcde85881 | 170 | drum(4,false); |
38 | 0:cd5fcde85881 | 171 | npx.off(); |
38 | 0:cd5fcde85881 | 172 | } |
38 | 0:cd5fcde85881 | 173 | void stop5(){ |
38 | 0:cd5fcde85881 | 174 | drum(5,false); |
38 | 0:cd5fcde85881 | 175 | npx.off(); |
38 | 0:cd5fcde85881 | 176 | } |
38 | 0:cd5fcde85881 | 177 | void stop6(){ |
38 | 0:cd5fcde85881 | 178 | drum(6,false); |
38 | 0:cd5fcde85881 | 179 | npx.off(); |
38 | 0:cd5fcde85881 | 180 | } |
38 | 0:cd5fcde85881 | 181 | void stop7(){ |
38 | 0:cd5fcde85881 | 182 | drum(7,false); |
38 | 0:cd5fcde85881 | 183 | npx.off(); |
38 | 0:cd5fcde85881 | 184 | } |
38 | 0:cd5fcde85881 | 185 | void stop8(){ |
38 | 0:cd5fcde85881 | 186 | drum(8,false); |
38 | 0:cd5fcde85881 | 187 | npx.off(); |
38 | 0:cd5fcde85881 | 188 | } |
38 | 0:cd5fcde85881 | 189 | void stop9(){ |
38 | 0:cd5fcde85881 | 190 | drum(9,false); |
38 | 0:cd5fcde85881 | 191 | npx.off(); |
38 | 0:cd5fcde85881 | 192 | } |
38 | 0:cd5fcde85881 | 193 | void stop10(){ |
38 | 0:cd5fcde85881 | 194 | drum(10,false); |
38 | 0:cd5fcde85881 | 195 | npx.off(); |
38 | 0:cd5fcde85881 | 196 | } |
38 | 0:cd5fcde85881 | 197 | void stop11(){ |
38 | 0:cd5fcde85881 | 198 | drum(11,false); |
38 | 0:cd5fcde85881 | 199 | npx.off(); |
38 | 0:cd5fcde85881 | 200 | } |
38 | 0:cd5fcde85881 | 201 | void stop12(){ |
38 | 0:cd5fcde85881 | 202 | drum(12,false); |
38 | 0:cd5fcde85881 | 203 | } |
38 | 0:cd5fcde85881 | 204 | void stop13(){ |
38 | 0:cd5fcde85881 | 205 | drum(13,false); |
38 | 0:cd5fcde85881 | 206 | } |
38 | 0:cd5fcde85881 | 207 | |
38 | 0:cd5fcde85881 | 208 | void light_2(){ |
38 | 0:cd5fcde85881 | 209 | if(solenoid[1] == true){ |
38 | 0:cd5fcde85881 | 210 | tape_led[0] = true; |
38 | 0:cd5fcde85881 | 211 | light_drum_2(); |
38 | 0:cd5fcde85881 | 212 | } |
38 | 0:cd5fcde85881 | 213 | } |
38 | 0:cd5fcde85881 | 214 | |
38 | 0:cd5fcde85881 | 215 | void light_2_1(){ |
38 | 0:cd5fcde85881 | 216 | if(solenoid[2] == true){ |
38 | 0:cd5fcde85881 | 217 | tape_led[0] = true; |
38 | 0:cd5fcde85881 | 218 | light_drum_2_1(); |
38 | 0:cd5fcde85881 | 219 | } |
38 | 0:cd5fcde85881 | 220 | } |
38 | 0:cd5fcde85881 | 221 | |
38 | 0:cd5fcde85881 | 222 | void light_3(){ |
38 | 0:cd5fcde85881 | 223 | if(solenoid[3] == true){ |
38 | 0:cd5fcde85881 | 224 | tape_led[1] = true; |
38 | 0:cd5fcde85881 | 225 | light_drum_3(); |
38 | 0:cd5fcde85881 | 226 | } |
38 | 0:cd5fcde85881 | 227 | } |
38 | 0:cd5fcde85881 | 228 | |
38 | 0:cd5fcde85881 | 229 | void light_4(){ |
38 | 0:cd5fcde85881 | 230 | if(solenoid[4] == true){ |
38 | 0:cd5fcde85881 | 231 | tape_led[2] = true; |
38 | 0:cd5fcde85881 | 232 | light_drum_4(); |
38 | 0:cd5fcde85881 | 233 | } |
38 | 0:cd5fcde85881 | 234 | } |
38 | 0:cd5fcde85881 | 235 | |
38 | 0:cd5fcde85881 | 236 | void light_5(){ |
38 | 0:cd5fcde85881 | 237 | if(solenoid[5] == true){ |
38 | 0:cd5fcde85881 | 238 | tape_led[3] = true; |
38 | 0:cd5fcde85881 | 239 | light_drum_5(); |
38 | 0:cd5fcde85881 | 240 | } |
38 | 0:cd5fcde85881 | 241 | } |
38 | 0:cd5fcde85881 | 242 | |
38 | 0:cd5fcde85881 | 243 | void light_5_1(){ |
38 | 0:cd5fcde85881 | 244 | if(solenoid[6] == true){ |
38 | 0:cd5fcde85881 | 245 | tape_led[3] = true; |
38 | 0:cd5fcde85881 | 246 | light_drum_5_1(); |
38 | 0:cd5fcde85881 | 247 | } |
38 | 0:cd5fcde85881 | 248 | } |
38 | 0:cd5fcde85881 | 249 | |
38 | 0:cd5fcde85881 | 250 | void light_c_1(){ |
38 | 0:cd5fcde85881 | 251 | if(solenoid[7] == true){ |
38 | 0:cd5fcde85881 | 252 | tape_led[4] = true; |
38 | 0:cd5fcde85881 | 253 | light_cymbal_1(); |
38 | 0:cd5fcde85881 | 254 | } |
38 | 0:cd5fcde85881 | 255 | } |
38 | 0:cd5fcde85881 | 256 | |
38 | 0:cd5fcde85881 | 257 | void light_c_1_1(){ |
38 | 0:cd5fcde85881 | 258 | if(solenoid[8] == true){ |
38 | 0:cd5fcde85881 | 259 | tape_led[4] = true; |
38 | 0:cd5fcde85881 | 260 | light_cymbal_1_1(); |
38 | 0:cd5fcde85881 | 261 | } |
38 | 0:cd5fcde85881 | 262 | } |
38 | 0:cd5fcde85881 | 263 | |
38 | 0:cd5fcde85881 | 264 | void light_c_2(){ |
38 | 0:cd5fcde85881 | 265 | if(solenoid[9] == true){ |
38 | 0:cd5fcde85881 | 266 | tape_led[5] = true; |
38 | 0:cd5fcde85881 | 267 | light_cymbal_2(); |
38 | 0:cd5fcde85881 | 268 | } |
38 | 0:cd5fcde85881 | 269 | } |
38 | 0:cd5fcde85881 | 270 | |
38 | 0:cd5fcde85881 | 271 | void light_c_3(){ |
38 | 0:cd5fcde85881 | 272 | if(solenoid[10] == true){ |
38 | 0:cd5fcde85881 | 273 | tape_led[6] = true; |
38 | 0:cd5fcde85881 | 274 | light_cymbal_3(); |
38 | 0:cd5fcde85881 | 275 | } |
38 | 0:cd5fcde85881 | 276 | } |
38 | 0:cd5fcde85881 | 277 | |
38 | 0:cd5fcde85881 | 278 | void light_c_4(){ |
38 | 0:cd5fcde85881 | 279 | if(solenoid[11] == true){ |
38 | 0:cd5fcde85881 | 280 | tape_led[7] = true; |
38 | 0:cd5fcde85881 | 281 | light_cymbal_4(); |
38 | 0:cd5fcde85881 | 282 | } |
38 | 0:cd5fcde85881 | 283 | } |
38 | 0:cd5fcde85881 | 284 | |
38 | 0:cd5fcde85881 | 285 | void play(note_t note){ |
38 | 0:cd5fcde85881 | 286 | if(note.hit < 11){ |
38 | 0:cd5fcde85881 | 287 | led_flag[note.hit] = true; |
38 | 0:cd5fcde85881 | 288 | } |
38 | 0:cd5fcde85881 | 289 | switch (note.hit){ |
38 | 0:cd5fcde85881 | 290 | case drum_1: |
38 | 0:cd5fcde85881 | 291 | driveMotor(0,0.3); |
38 | 0:cd5fcde85881 | 292 | break; |
38 | 0:cd5fcde85881 | 293 | |
38 | 0:cd5fcde85881 | 294 | case drum_2: |
38 | 0:cd5fcde85881 | 295 | on_off = true; |
38 | 0:cd5fcde85881 | 296 | drum(note.hit,true); |
38 | 0:cd5fcde85881 | 297 | stop_1.attach_us(stop1,50000); |
38 | 0:cd5fcde85881 | 298 | break; |
38 | 0:cd5fcde85881 | 299 | |
38 | 0:cd5fcde85881 | 300 | |
38 | 0:cd5fcde85881 | 301 | case drum_2_1: |
38 | 0:cd5fcde85881 | 302 | on_off = true; |
38 | 0:cd5fcde85881 | 303 | drum(note.hit,true); |
38 | 0:cd5fcde85881 | 304 | stop_2.attach_us(stop2,50000); |
38 | 0:cd5fcde85881 | 305 | break; |
38 | 0:cd5fcde85881 | 306 | |
38 | 0:cd5fcde85881 | 307 | |
38 | 0:cd5fcde85881 | 308 | case drum_3: |
38 | 0:cd5fcde85881 | 309 | on_off = true; |
38 | 0:cd5fcde85881 | 310 | drum(note.hit,true); |
38 | 0:cd5fcde85881 | 311 | stop_3.attach_us(stop3,50000); |
38 | 0:cd5fcde85881 | 312 | break; |
38 | 0:cd5fcde85881 | 313 | |
38 | 0:cd5fcde85881 | 314 | case drum_4: |
38 | 0:cd5fcde85881 | 315 | on_off = true; |
38 | 0:cd5fcde85881 | 316 | drum(note.hit,true); |
38 | 0:cd5fcde85881 | 317 | stop_4.attach_us(stop4,50000); |
38 | 0:cd5fcde85881 | 318 | break; |
38 | 0:cd5fcde85881 | 319 | |
38 | 0:cd5fcde85881 | 320 | case drum_5: |
38 | 0:cd5fcde85881 | 321 | on_off = true; |
38 | 0:cd5fcde85881 | 322 | drum(note.hit,true); |
38 | 0:cd5fcde85881 | 323 | stop_5.attach_us(stop5,50000); |
38 | 0:cd5fcde85881 | 324 | break; |
38 | 0:cd5fcde85881 | 325 | |
38 | 0:cd5fcde85881 | 326 | case drum_5_1: |
38 | 0:cd5fcde85881 | 327 | on_off = true; |
38 | 0:cd5fcde85881 | 328 | drum(note.hit,true); |
38 | 0:cd5fcde85881 | 329 | stop_6.attach_us(stop6,50000); |
38 | 0:cd5fcde85881 | 330 | break; |
38 | 0:cd5fcde85881 | 331 | |
38 | 0:cd5fcde85881 | 332 | case cymbal_1: |
38 | 0:cd5fcde85881 | 333 | on_off = true; |
38 | 0:cd5fcde85881 | 334 | drum(note.hit,true); |
38 | 0:cd5fcde85881 | 335 | stop_7.attach_us(stop7,50000); |
38 | 0:cd5fcde85881 | 336 | break; |
38 | 0:cd5fcde85881 | 337 | |
38 | 0:cd5fcde85881 | 338 | case cymbal_1_1: |
38 | 0:cd5fcde85881 | 339 | on_off = true; |
38 | 0:cd5fcde85881 | 340 | drum(note.hit,true); |
38 | 0:cd5fcde85881 | 341 | stop_8.attach_us(stop8,50000); |
38 | 0:cd5fcde85881 | 342 | break; |
38 | 0:cd5fcde85881 | 343 | |
38 | 0:cd5fcde85881 | 344 | case cymbal_2: |
38 | 0:cd5fcde85881 | 345 | on_off = true; |
38 | 0:cd5fcde85881 | 346 | drum(note.hit,true); |
38 | 0:cd5fcde85881 | 347 | stop_9.attach_us(stop9,50000); |
38 | 0:cd5fcde85881 | 348 | break; |
38 | 0:cd5fcde85881 | 349 | |
38 | 0:cd5fcde85881 | 350 | case cymbal_3: |
38 | 0:cd5fcde85881 | 351 | on_off = true; |
38 | 0:cd5fcde85881 | 352 | drum(note.hit,true); |
38 | 0:cd5fcde85881 | 353 | stop_10.attach_us(stop10,50000); |
38 | 0:cd5fcde85881 | 354 | break; |
38 | 0:cd5fcde85881 | 355 | |
38 | 0:cd5fcde85881 | 356 | case cymbal_4: |
38 | 0:cd5fcde85881 | 357 | on_off = true; |
38 | 0:cd5fcde85881 | 358 | drum(note.hit,true); |
38 | 0:cd5fcde85881 | 359 | stop_11.attach_us(stop11,50000); |
38 | 0:cd5fcde85881 | 360 | break; |
38 | 0:cd5fcde85881 | 361 | |
38 | 0:cd5fcde85881 | 362 | case hihat_off: |
38 | 0:cd5fcde85881 | 363 | on_off = true; |
38 | 0:cd5fcde85881 | 364 | drum(note.hit,true); |
38 | 0:cd5fcde85881 | 365 | stop_12.attach_us(stop12,50000); |
38 | 0:cd5fcde85881 | 366 | break; |
38 | 0:cd5fcde85881 | 367 | |
38 | 0:cd5fcde85881 | 368 | case hihat_middle: |
38 | 0:cd5fcde85881 | 369 | on_off = true; |
38 | 0:cd5fcde85881 | 370 | drum(note.hit,true); |
38 | 0:cd5fcde85881 | 371 | stop_13.attach_us(stop13,50000); |
38 | 0:cd5fcde85881 | 372 | break; |
38 | 0:cd5fcde85881 | 373 | |
38 | 0:cd5fcde85881 | 374 | case rest: |
38 | 0:cd5fcde85881 | 375 | on_off = false; |
38 | 0:cd5fcde85881 | 376 | |
38 | 0:cd5fcde85881 | 377 | default: |
38 | 0:cd5fcde85881 | 378 | break; |
38 | 0:cd5fcde85881 | 379 | } |
38 | 0:cd5fcde85881 | 380 | } |
38 | 0:cd5fcde85881 | 381 | |
38 | 0:cd5fcde85881 | 382 | void limitswitch_stop(){ |
38 | 0:cd5fcde85881 | 383 | drum_1_stop.attach_us(stop0,140000); |
38 | 0:cd5fcde85881 | 384 | } |
38 | 0:cd5fcde85881 | 385 | |
38 | 0:cd5fcde85881 | 386 | |
38 | 0:cd5fcde85881 | 387 | Timer timer; |
38 | 0:cd5fcde85881 | 388 | Timer measure; |
38 | 0:cd5fcde85881 | 389 | |
38 | 0:cd5fcde85881 | 390 | void druming(int numtime, const note_t* note, int num){ |
38 | 0:cd5fcde85881 | 391 | static int i, j; |
38 | 0:cd5fcde85881 | 392 | static bool already; |
38 | 0:cd5fcde85881 | 393 | |
38 | 0:cd5fcde85881 | 394 | for (i = 0; i < numtime && status == prev_status; i++) { |
38 | 0:cd5fcde85881 | 395 | measure.reset(); |
38 | 0:cd5fcde85881 | 396 | timer.reset(); |
38 | 0:cd5fcde85881 | 397 | for (j = 0; j < num; j++) { |
38 | 0:cd5fcde85881 | 398 | |
38 | 0:cd5fcde85881 | 399 | while (note[j].time > timer.read_us()) { |
38 | 0:cd5fcde85881 | 400 | if(note[j].time - timer.read_us() > 0.3 && !already){ |
38 | 0:cd5fcde85881 | 401 | /*for(k = 1;k<12;k++){ |
38 | 0:cd5fcde85881 | 402 | if(led_flag[k]){ |
38 | 0:cd5fcde85881 | 403 | func[k](); |
38 | 0:cd5fcde85881 | 404 | led_flag[k] = false; |
38 | 0:cd5fcde85881 | 405 | } |
38 | 0:cd5fcde85881 | 406 | }*/ |
38 | 0:cd5fcde85881 | 407 | npx.show(); |
38 | 0:cd5fcde85881 | 408 | already = true; |
38 | 0:cd5fcde85881 | 409 | }else if(note[j].time - timer.read_us() < 0.05 && already){ |
38 | 0:cd5fcde85881 | 410 | npx.off(); |
38 | 0:cd5fcde85881 | 411 | already = false; |
38 | 0:cd5fcde85881 | 412 | } |
38 | 0:cd5fcde85881 | 413 | } |
38 | 0:cd5fcde85881 | 414 | play(note[j]); |
38 | 0:cd5fcde85881 | 415 | timer.reset(); |
38 | 0:cd5fcde85881 | 416 | } |
38 | 0:cd5fcde85881 | 417 | while(measure.read_us() < onemeasure); |
38 | 0:cd5fcde85881 | 418 | } |
38 | 0:cd5fcde85881 | 419 | } |
38 | 0:cd5fcde85881 | 420 | |
38 | 0:cd5fcde85881 | 421 | void druming2(int numtime, const note_t* note, int num){ |
38 | 0:cd5fcde85881 | 422 | static int i, j; |
38 | 0:cd5fcde85881 | 423 | static bool already; |
38 | 0:cd5fcde85881 | 424 | |
38 | 0:cd5fcde85881 | 425 | for (i = 0; i < numtime && status == prev_status; i++) { |
38 | 0:cd5fcde85881 | 426 | measure.reset(); |
38 | 0:cd5fcde85881 | 427 | timer.reset(); |
38 | 0:cd5fcde85881 | 428 | for (j = 0; j < num; j++) { |
38 | 0:cd5fcde85881 | 429 | while (note[j].time > timer.read_us()) { |
38 | 0:cd5fcde85881 | 430 | if(note[j].time - timer.read_us() > 0.3 && !already){ |
38 | 0:cd5fcde85881 | 431 | npx.show(); |
38 | 0:cd5fcde85881 | 432 | already = true; |
38 | 0:cd5fcde85881 | 433 | }else if(note[j].time - timer.read_us() < 0.05 && already){ |
38 | 0:cd5fcde85881 | 434 | npx.off(); |
38 | 0:cd5fcde85881 | 435 | already = false; |
38 | 0:cd5fcde85881 | 436 | } |
38 | 0:cd5fcde85881 | 437 | } |
38 | 0:cd5fcde85881 | 438 | play(note[j]); |
38 | 0:cd5fcde85881 | 439 | timer.reset(); |
38 | 0:cd5fcde85881 | 440 | } |
38 | 0:cd5fcde85881 | 441 | while(measure.read_us() < onemeasure_2); |
38 | 0:cd5fcde85881 | 442 | } |
38 | 0:cd5fcde85881 | 443 | } |
38 | 0:cd5fcde85881 | 444 | |
38 | 0:cd5fcde85881 | 445 | bool test(int rx_data,int &tx_data){ |
38 | 0:cd5fcde85881 | 446 | drum(rx_data,true); |
38 | 0:cd5fcde85881 | 447 | wait(1); |
38 | 0:cd5fcde85881 | 448 | drum(rx_data,false); |
38 | 0:cd5fcde85881 | 449 | return true; |
38 | 0:cd5fcde85881 | 450 | } |
38 | 0:cd5fcde85881 | 451 | |
38 | 0:cd5fcde85881 | 452 | int main(){ |
38 | 0:cd5fcde85881 | 453 | timekeeper_1.start(); |
38 | 0:cd5fcde85881 | 454 | limit_switch.rise(limitswitch_stop); |
38 | 0:cd5fcde85881 | 455 | |
38 | 0:cd5fcde85881 | 456 | |
38 | 0:cd5fcde85881 | 457 | slave.addCMD(255, pause); |
38 | 0:cd5fcde85881 | 458 | slave.addCMD(2, command0); |
38 | 0:cd5fcde85881 | 459 | slave.addCMD(3, setup); |
38 | 0:cd5fcde85881 | 460 | slave.addCMD(4, test); |
38 | 0:cd5fcde85881 | 461 | |
38 | 0:cd5fcde85881 | 462 | npx.global_scale = 1.0f; |
38 | 0:cd5fcde85881 | 463 | npx.normalize = false; |
38 | 0:cd5fcde85881 | 464 | |
38 | 0:cd5fcde85881 | 465 | motor_pin[0][0].period_us(20); |
38 | 0:cd5fcde85881 | 466 | motor_pin[0][1].period_us(20); |
38 | 0:cd5fcde85881 | 467 | |
38 | 0:cd5fcde85881 | 468 | func[1] = light_2; |
38 | 0:cd5fcde85881 | 469 | func[2] = light_2_1; |
38 | 0:cd5fcde85881 | 470 | func[3] = light_3; |
38 | 0:cd5fcde85881 | 471 | func[4] = light_4; |
38 | 0:cd5fcde85881 | 472 | func[5] = light_5; |
38 | 0:cd5fcde85881 | 473 | func[6] = light_5_1; |
38 | 0:cd5fcde85881 | 474 | func[7] = light_c_1; |
38 | 0:cd5fcde85881 | 475 | func[8] = light_c_1_1; |
38 | 0:cd5fcde85881 | 476 | func[9] = light_c_2; |
38 | 0:cd5fcde85881 | 477 | func[10] = light_c_3; |
38 | 0:cd5fcde85881 | 478 | func[11] = light_c_4; |
38 | 0:cd5fcde85881 | 479 | |
38 | 0:cd5fcde85881 | 480 | timer.start(); |
38 | 0:cd5fcde85881 | 481 | measure.start(); |
38 | 0:cd5fcde85881 | 482 | while(1) { |
38 | 0:cd5fcde85881 | 483 | |
38 | 0:cd5fcde85881 | 484 | prev_status = status; |
38 | 0:cd5fcde85881 | 485 | switch (status) { |
38 | 0:cd5fcde85881 | 486 | case 0: |
38 | 0:cd5fcde85881 | 487 | break; |
38 | 0:cd5fcde85881 | 488 | case 1: |
38 | 0:cd5fcde85881 | 489 | checkpoint1(); |
38 | 0:cd5fcde85881 | 490 | if(status == prev_status) { |
38 | 0:cd5fcde85881 | 491 | status=2; |
38 | 0:cd5fcde85881 | 492 | } |
38 | 0:cd5fcde85881 | 493 | break; |
38 | 0:cd5fcde85881 | 494 | case 2: |
38 | 0:cd5fcde85881 | 495 | checkpoint2(); |
38 | 0:cd5fcde85881 | 496 | if(status == prev_status) { |
38 | 0:cd5fcde85881 | 497 | status=100; |
38 | 0:cd5fcde85881 | 498 | } |
38 | 0:cd5fcde85881 | 499 | break; |
38 | 0:cd5fcde85881 | 500 | //↓無我夢中 |
38 | 0:cd5fcde85881 | 501 | case 11: |
38 | 0:cd5fcde85881 | 502 | checkpoint1_2(); |
38 | 0:cd5fcde85881 | 503 | if(status == prev_status) { |
38 | 0:cd5fcde85881 | 504 | status=38; |
38 | 0:cd5fcde85881 | 505 | } |
38 | 0:cd5fcde85881 | 506 | break; |
38 | 0:cd5fcde85881 | 507 | |
38 | 0:cd5fcde85881 | 508 | case 38: |
38 | 0:cd5fcde85881 | 509 | break; |
38 | 0:cd5fcde85881 | 510 | |
38 | 0:cd5fcde85881 | 511 | case 99: |
38 | 0:cd5fcde85881 | 512 | checkpoint(); |
38 | 0:cd5fcde85881 | 513 | status=38; |
38 | 0:cd5fcde85881 | 514 | break; |
38 | 0:cd5fcde85881 | 515 | } |
38 | 0:cd5fcde85881 | 516 | } |
38 | 0:cd5fcde85881 | 517 | } |
38 | 0:cd5fcde85881 | 518 | |
38 | 0:cd5fcde85881 | 519 | void checkpoint(){ |
38 | 0:cd5fcde85881 | 520 | druming(1,astro::mearsure,12); |
38 | 0:cd5fcde85881 | 521 | } |
38 | 0:cd5fcde85881 | 522 | |
38 | 0:cd5fcde85881 | 523 | void checkpoint1(){ |
38 | 0:cd5fcde85881 | 524 | druming(3,astro::blank,4); |
38 | 0:cd5fcde85881 | 525 | druming(1,astro::mearsure_1,7); |
38 | 0:cd5fcde85881 | 526 | druming(1,astro::mearsure_2,17); |
38 | 0:cd5fcde85881 | 527 | druming(3,astro::mearsure_3,20); |
38 | 0:cd5fcde85881 | 528 | druming(1,astro::mearsure_4,11); |
38 | 0:cd5fcde85881 | 529 | druming(1,astro::mearsure_5,11); |
38 | 0:cd5fcde85881 | 530 | druming(1,astro::mearsure_6,17); |
38 | 0:cd5fcde85881 | 531 | druming(6,astro::mearsure_7,20); |
38 | 0:cd5fcde85881 | 532 | druming(1,astro::mearsure_8,20); |
38 | 0:cd5fcde85881 | 533 | druming(1,astro::mearsure_6,17); |
38 | 0:cd5fcde85881 | 534 | druming(1,astro::mearsure_9,17); |
38 | 0:cd5fcde85881 | 535 | druming(1,astro::mearsure_10,18); |
38 | 0:cd5fcde85881 | 536 | druming(1,astro::mearsure_9,17); |
38 | 0:cd5fcde85881 | 537 | druming(1,astro::mearsure_10,18); |
38 | 0:cd5fcde85881 | 538 | druming(1,astro::mearsure_9,17); |
38 | 0:cd5fcde85881 | 539 | druming(1,astro::mearsure_10,18); |
38 | 0:cd5fcde85881 | 540 | druming(1,astro::mearsure_11,14); |
38 | 0:cd5fcde85881 | 541 | druming(1,astro::mearsure_6,17); |
38 | 0:cd5fcde85881 | 542 | druming(2,astro::mearsure_7,20); |
38 | 0:cd5fcde85881 | 543 | druming(1,astro::mearsure_12,14); |
38 | 0:cd5fcde85881 | 544 | druming(2,astro::mearsure_13,12); |
38 | 0:cd5fcde85881 | 545 | druming(1,astro::mearsure_14,8); |
38 | 0:cd5fcde85881 | 546 | druming(1,astro::mearsure_15,13); |
38 | 0:cd5fcde85881 | 547 | druming(1,astro::mearsure_6,17); |
38 | 0:cd5fcde85881 | 548 | druming(1,astro::mearsure_16,21); |
38 | 0:cd5fcde85881 | 549 | druming(1,astro::mearsure_7,20); |
38 | 0:cd5fcde85881 | 550 | druming(1,astro::mearsure_16,21); |
38 | 0:cd5fcde85881 | 551 | druming(1,astro::mearsure_7,20); |
38 | 0:cd5fcde85881 | 552 | druming(1,astro::mearsure_16,21); |
38 | 0:cd5fcde85881 | 553 | druming(1,astro::mearsure_17,17); |
38 | 0:cd5fcde85881 | 554 | druming(1,astro::mearsure_18,21); |
38 | 0:cd5fcde85881 | 555 | druming(1,astro::mearsure_19,10); |
38 | 0:cd5fcde85881 | 556 | druming(1,astro::mearsure_20,11); |
38 | 0:cd5fcde85881 | 557 | druming(1,astro::mearsure_19,10); |
38 | 0:cd5fcde85881 | 558 | druming(3,astro::mearsure_20,11); |
38 | 0:cd5fcde85881 | 559 | druming(1,astro::mearsure_21,12); |
38 | 0:cd5fcde85881 | 560 | druming(1,astro::mearsure_22,12); |
38 | 0:cd5fcde85881 | 561 | druming(1,astro::mearsure_23,13); |
38 | 0:cd5fcde85881 | 562 | druming(1,astro::mearsure_24,7); |
38 | 0:cd5fcde85881 | 563 | }//一番最後まで |
38 | 0:cd5fcde85881 | 564 | |
38 | 0:cd5fcde85881 | 565 | void checkpoint2(){ |
38 | 0:cd5fcde85881 | 566 | druming(1,astro::mearsure_6,17); |
38 | 0:cd5fcde85881 | 567 | druming(2,astro::mearsure_7,20); |
38 | 0:cd5fcde85881 | 568 | druming(1,astro::mearsure_8,20); |
38 | 0:cd5fcde85881 | 569 | druming(2,astro::mearsure_25,15); |
38 | 0:cd5fcde85881 | 570 | druming(1,astro::mearsure_26,10); |
38 | 0:cd5fcde85881 | 571 | druming(1,astro::mearsure_27,13); |
38 | 0:cd5fcde85881 | 572 | druming(1,astro::mearsure_10,18); |
38 | 0:cd5fcde85881 | 573 | druming(6,astro::mearsure_7,20); |
38 | 0:cd5fcde85881 | 574 | druming(1,astro::mearsure_28,15); |
38 | 0:cd5fcde85881 | 575 | druming(1,astro::mearsure_10,18); |
38 | 0:cd5fcde85881 | 576 | druming(1,astro::mearsure_16,21); |
38 | 0:cd5fcde85881 | 577 | druming(1,astro::mearsure_7,20); |
38 | 0:cd5fcde85881 | 578 | druming(1,astro::mearsure_16,21); |
38 | 0:cd5fcde85881 | 579 | druming(1,astro::mearsure_35,18); |
38 | 0:cd5fcde85881 | 580 | druming(1,astro::mearsure_29,9); |
38 | 0:cd5fcde85881 | 581 | druming(1,astro::mearsure_30,8); |
38 | 0:cd5fcde85881 | 582 | druming(1,astro::mearsure_31,11); |
38 | 0:cd5fcde85881 | 583 | druming(1,astro::mearsure_23,13); |
38 | 0:cd5fcde85881 | 584 | druming(1,astro::mearsure_39,5); |
38 | 0:cd5fcde85881 | 585 | druming(1,astro::mearsure_35,18); |
38 | 0:cd5fcde85881 | 586 | druming(1,astro::mearsure_36,11); |
38 | 0:cd5fcde85881 | 587 | druming(1,astro::mearsure_37,12); |
38 | 0:cd5fcde85881 | 588 | druming(1,astro::mearsure_38,8); |
38 | 0:cd5fcde85881 | 589 | druming(1,astro::mearsure_33,5); |
38 | 0:cd5fcde85881 | 590 | druming(1,astro::mearsure_34,6); |
38 | 0:cd5fcde85881 | 591 | druming(2,astro::blank,4); |
38 | 0:cd5fcde85881 | 592 | }//天体観測終り |
38 | 0:cd5fcde85881 | 593 | |
38 | 0:cd5fcde85881 | 594 | void checkpoint1_2(){ |
38 | 0:cd5fcde85881 | 595 | druming(17,muga::blank_2,4); |
38 | 0:cd5fcde85881 | 596 | druming2(3,muga::mearsure_1_2,9); |
38 | 0:cd5fcde85881 | 597 | druming2(1,muga::mearsure_2_2,8); |
38 | 0:cd5fcde85881 | 598 | druming2(3,muga::mearsure_1_2,9); |
38 | 0:cd5fcde85881 | 599 | druming2(1,muga::mearsure_3_2,22); |
38 | 0:cd5fcde85881 | 600 | druming2(1,muga::mearsure_4_2,15); |
38 | 0:cd5fcde85881 | 601 | druming2(1,muga::mearsure_5_2,20); |
38 | 0:cd5fcde85881 | 602 | druming2(1,muga::mearsure_6_2,22); |
38 | 0:cd5fcde85881 | 603 | druming2(1,muga::mearsure_7_2,21); |
38 | 0:cd5fcde85881 | 604 | druming2(1,muga::mearsure_8_2,22); |
38 | 0:cd5fcde85881 | 605 | druming2(1,muga::mearsure_7_2,21); |
38 | 0:cd5fcde85881 | 606 | druming2(1,muga::mearsure_6_2,22); |
38 | 0:cd5fcde85881 | 607 | druming2(1,muga::mearsure_7_2,21); |
38 | 0:cd5fcde85881 | 608 | druming2(1,muga::mearsure_9_2,23); |
38 | 0:cd5fcde85881 | 609 | druming2(1,muga::mearsure_5_2,20); |
38 | 0:cd5fcde85881 | 610 | druming2(2,muga::mearsure_7_2,21); |
38 | 0:cd5fcde85881 | 611 | druming2(1,muga::mearsure_8_2,22); |
38 | 0:cd5fcde85881 | 612 | druming2(1,muga::mearsure_7_2,21); |
38 | 0:cd5fcde85881 | 613 | druming2(1,muga::mearsure_8_2,22); |
38 | 0:cd5fcde85881 | 614 | druming2(1,muga::mearsure_7_2,21); |
38 | 0:cd5fcde85881 | 615 | druming2(1,muga::mearsure_10_2,22); |
38 | 0:cd5fcde85881 | 616 | druming2(1,muga::mearsure_5_2,20); |
38 | 0:cd5fcde85881 | 617 | druming2(1,muga::mearsure_7_2,21); |
38 | 0:cd5fcde85881 | 618 | druming2(1,muga::mearsure_8_2,22); |
38 | 0:cd5fcde85881 | 619 | druming2(1,muga::mearsure_11_2,9); |
38 | 0:cd5fcde85881 | 620 | druming2(1,muga::mearsure_12_2,21); |
38 | 0:cd5fcde85881 | 621 | druming2(2,muga::mearsure_8_2,22); |
38 | 0:cd5fcde85881 | 622 | druming2(1,muga::mearsure_13_2,20); |
38 | 0:cd5fcde85881 | 623 | druming2(1,muga::mearsure_14_2,5); |
38 | 0:cd5fcde85881 | 624 | druming2(3,muga::blank_2,4); |
38 | 0:cd5fcde85881 | 625 | druming2(1,muga::mearsure_15_2,11); |
38 | 0:cd5fcde85881 | 626 | druming2(1,muga::mearsure_16_2,1); |
38 | 0:cd5fcde85881 | 627 | druming2(1,muga::mearsure_17_2,7); |
38 | 0:cd5fcde85881 | 628 | druming2(1,muga::mearsure_18_2,16); |
38 | 0:cd5fcde85881 | 629 | druming2(1,muga::mearsure_19_2,22); |
38 | 0:cd5fcde85881 | 630 | druming2(6,muga::mearsure_20_2,23); |
38 | 0:cd5fcde85881 | 631 | druming2(1,muga::mearsure_21_2,20); |
38 | 0:cd5fcde85881 | 632 | druming2(1,muga::mearsure_19_2,22); |
38 | 0:cd5fcde85881 | 633 | druming2(2,muga::mearsure_20_2,23); |
38 | 0:cd5fcde85881 | 634 | druming2(1,muga::mearsure_22_2,22); |
38 | 0:cd5fcde85881 | 635 | } |
38 | 0:cd5fcde85881 | 636 | |
38 | 0:cd5fcde85881 | 637 | |
38 | 0:cd5fcde85881 | 638 | /*ハイハット中間の時→hihat_middle |
38 | 0:cd5fcde85881 | 639 | ハイハットCLOSE→hihat_off |
38 | 0:cd5fcde85881 | 640 | 左が半踏み真ん中が完全に閉まる |
38 | 0:cd5fcde85881 | 641 | |
38 | 0:cd5fcde85881 | 642 | 左上⇒ハイハット//1,2 |
38 | 0:cd5fcde85881 | 643 | 左下⇒スネアドラム//3,4 |
38 | 0:cd5fcde85881 | 644 | 真ん中上⇒クラッシュ_low//1 |
38 | 0:cd5fcde85881 | 645 | 真ん中下⇒ハイタム//2・ロータム//3 |
38 | 0:cd5fcde85881 | 646 | 右上⇒ライドシンバル//1・クラッシュ_hight//2 |
38 | 0:cd5fcde85881 | 647 | 右下⇒フロアタム//3,4*/ |