Components and supplies
Zener Diode - 5.1V 1W
Resistor 1M ohm
USB-A to B Cable
Resistor 10k ohm
Standard LCD - 16x2 White on Blue
Arduino UNO
Force Sensitive Resistor (FSR)
Piezo
Lightning to USB Camera Adapter
Pushbutton switch 12mm
Slide Switch
TRS Socket
Tools and machines
Laser cutter (generic)
3D Printer (generic)
circle cutter
Soldering iron (generic)
Apps and platforms
Arduino IDE
Project description
Code
Hello Drum v2
arduino
Modified: 05/12/2019 by George Brotherston
1/* 2 Drum MIDI Controller 3 Created: 28/06/2017 by Ryo Kosaka as " HELLO DRUM " Ver.1.0 4 Modified: 05/12/2019 by George Brotherston 5*/ 6 7// Library Includes 8 9// #include <Arduino.h> // Arduino Library (automatically included) 10 // LOW (Line 41) 11 // HIGH (Line 40) 12 // INPUT_PULLUP (Line 47) 13 // digitalRead() (Line 177) 14 // analogRead() (Line 178) 15 #include <MIDI.h> // MIDI Library - Version: 4.3.1 16 // includes <midi_Namespace.h> 17 // class MIDI (Line 30) 18 // class method 'begin' (Line 55) 19 #include <LiquidCrystal.h> // LiquidCrystal - Version: 1.0.7 20 // lcd object instantiatied (in Variables section below) from LiquidCrystal class (Line 45) 21 22// Variables - Declare and Initialize 23 24 // Variables - Program 25 boolean bSnareFlag = false; 26 boolean bHihatFlag = false; 27 boolean bKickFlag = false; 28 boolean bPedalFlag = false; 29 boolean bButtonState = true; 30 boolean bButtonState_set = true; 31 int iUPDOWN = 0; 32 int iNEXTBACK = 0; 33 34 // Arrays - Program 35 // InstrumentSensor[6] = {threshold, sensitivity, note, flag, velocity, iPeakValue} 36 // 'iPeakValue' and 'velocity' must be zero for all InstrumentSensor arrays 37 // All 'aHIHAT[]' and 'aHIHAT_CLOSE[]' array elements should have the same value except for 'note' element. 38 int aSNARE[6] = {150, 950, 38, 3, 0, 0}; 39 int aSNARE_RIM[6] = {5, 500, 37, 3 , 0, 0}; 40 int aHIHAT[6] = {100, 800, 46, 1, 0, 0}; 41 int aHIHAT_CLOSE[6] = {100, 800, 42, 1, 0, 0}; 42 int aKICK[6] = {200, 700, 36, 1, 0, 0}; 43 // Instrument_ContinuousController[4] = {scantime, snare/rim, pedalVelocity , masktime} 44 int aHIHAT_PEDAL[4] = {600, 0, 44, 0}; 45 // InstrumentSensor_ParameterValue[4] = {threshold, sensitivity, note, flag} 46 int aSETTING[4] = {4, 500 ,100 ,1}; 47 48 // Libraries 49 // LiquidCrystal.h 50 // Constants (already defined in Library, still in scope? If not then define below) 51 // const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 52 // lcd object instantiatiated from LiquidCrystal class (LiquidCrystal.h Line 45) 53 LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // Associate LCD interface pins to associated Arduino pin number 54 // MIDI.h 55 // Initialize the library 56 MIDI_CREATE_DEFAULT_INSTANCE(); 57 58// Program Code 59 60 // Program Execution - Initial (program setup) 61 62 void setup() { 63 MIDI.begin(10); // begin (MIDI.h Line 55) 64 lcd.begin(16, 2); // begin (LiquidCrystal.h Line 62) 65 lcd.print("INITIALIZING..."); // print (LiquidCrystal.h Line 45) 66 lcd.setCursor(0, 1); // setCursor (LiquidCrystal.h Line 82) 67 lcd.print("DRUM MIDI CONTROLLER"); 68 pinMode(6, INPUT_PULLUP); // pinMode (Arduino.h Line 175); INPUT_PULLUP (Arduino.h Line 47) 69 pinMode(7, INPUT_PULLUP); 70 pinMode(8, INPUT_PULLUP); 71 pinMode(9, INPUT_PULLUP); 72 pinMode(10, INPUT_PULLUP); 73 } 74 75 // Program Execution - Steadystate (continuous loop until power is lost) 76 77 void loop() { 78 // Drum MIDI Controller Circuit 79 // Declare and Initialize Variables 80 81 int iButton_set = digitalRead(6); // Set Button // digitalRead() (Arduino.h Line 177) 82 int iButton_up = digitalRead(7); // Up Button 83 int iButton_down = digitalRead(8); // Down Button 84 int iButton_next = digitalRead(9); // Next Button 85 int iButton_back = digitalRead(10); // Back Button 86 int iPiezoValue_A0 = analogRead(A0); // Piezo - Snare Head // analogRead() (Arduino.h Line 178) 87 int iPiezoValue_A1 = analogRead(A1); // Piezo - Snare Rim 88 int iPiezoValue_A2 = analogRead(A2); // Hi-hat 89 int iPiezoValue_A3 = analogRead(A3); // Kick Drum 90 int iFSRValue_A4 = analogRead(A4); // Hi-hat Pedal 91 92 // Edit Mode 93 94 int aUP[4] = {5, 50, 1,1}; // {threshold, sensitivity, note, flag} 95 int aUP_ADVANCE[4] = {1, 50, 1,1}; // {scantime, rim/head, pedal velocity, masktime} 96 97 // Note: aINSTRUMENT[] array was not declared in 'Arrays' above 98 char* aINSTRUMENT[] = { 99 "SNARE HEAD", "SNARE RIM", "HIHAT OPEN", "HIHAT CLOSE", "HIHAT PEDAL", "KICK", "ADVANCED SETTING" 100 }; 101 102 // Note: aSETTING[] array WAS declared in 'Arrays' above 103 char* aSETTING[] = { 104 "THRESHOLD", "SENSITIVITY", "NOTE", "FLAG" 105 }; 106 107 // Note: aSETTING_ADVANCE[] was not declared in 'Arrays' above 108 char* aSETTING_ADVANCE[] = { 109 "SCAN TIME", "HEAD / RIM ","PEDAL VELO", "MASK TIME" 110 }; 111 112 if (iUPDOWN < 0) { 113 iUPDOWN = 6; 114 } 115 116 if (iUPDOWN > 6) { 117 iUPDOWN = 0; 118 } 119 120 if (iNEXTBACK < 0) { 121 iNEXTBACK = 3; 122 } 123 124 if (iNEXTBACK > 3) { 125 iNEXTBACK = 0; 126 } 127 128 // Pushbutton EDIT 129 // LOW (Arduino.h Line 41) 130 if (iButton_set == LOW && bButtonState == true && bButtonState_set == true) { 131 lcd.clear(); 132 lcd.print("EDIT"); 133 bButtonState = false; 134 bButtonState_set = false; 135 delay(500); 136 } 137 138 if (iButton_set == LOW && bButtonState == true && bButtonState_set == false) { 139 lcd.clear(); 140 lcd.print("EDIT DONE"); 141 bButtonState = false; 142 bButtonState_set = true; 143 delay(500); 144 } 145 146 if (iButton_up == LOW && bButtonState == true && bButtonState_set == false) { 147 switch (iUPDOWN) { 148 case 0: 149 aSNARE[iNEXTBACK] = aSNARE[iNEXTBACK] + aUP[iNEXTBACK]; 150 break; 151 152 case 1: 153 aSNARE_RIM[iNEXTBACK] = aSNARE_RIM[iNEXTBACK] + aUP[iNEXTBACK]; 154 break; 155 156 case 2: 157 switch (iNEXTBACK) { 158 case 2: 159 aHIHAT[iNEXTBACK] = aHIHAT[iNEXTBACK] + aUP[iNEXTBACK]; 160 break; 161 162 default: 163 aHIHAT_CLOSE[iNEXTBACK] = aHIHAT_CLOSE[iNEXTBACK] + aUP[iNEXTBACK]; 164 aHIHAT[iNEXTBACK] = aHIHAT[iNEXTBACK] + aUP[iNEXTBACK]; 165 } 166 break; 167 168 case 3: 169 switch (iNEXTBACK) { 170 case 2: 171 aHIHAT_CLOSE[iNEXTBACK] = aHIHAT_CLOSE[iNEXTBACK] + aUP[iNEXTBACK]; 172 break; 173 174 default: 175 aHIHAT_CLOSE[iNEXTBACK] = aHIHAT_CLOSE[iNEXTBACK] + aUP[iNEXTBACK]; 176 aHIHAT[iNEXTBACK] = aHIHAT[iNEXTBACK] + aUP[iNEXTBACK]; 177 } 178 break; 179 180 case 4: 181 switch (iNEXTBACK) { 182 case 0: 183 aHIHAT_PEDAL[iNEXTBACK] = aHIHAT_PEDAL[iNEXTBACK] + aUP[iNEXTBACK]; 184 break; 185 186 case 2: 187 aHIHAT_PEDAL[iNEXTBACK] = aHIHAT_PEDAL[iNEXTBACK] + aUP[iNEXTBACK]; 188 break; 189 } 190 break; 191 192 case 5: 193 aKICK[iNEXTBACK] = aKICK[iNEXTBACK] + aUP[iNEXTBACK]; 194 break; 195 196 case 6: 197 aSETTING[iNEXTBACK] = aSETTING[iNEXTBACK] + aUP_ADVANCE[iNEXTBACK]; 198 break; 199 } 200 bButtonState = false; 201 delay(30); 202 } 203 204 if (iButton_down == LOW && bButtonState == true && bButtonState_set == false) { 205 206 switch (iUPDOWN) { 207 case 0: 208 aSNARE[iNEXTBACK] = aSNARE[iNEXTBACK] - aUP[iNEXTBACK]; 209 break; 210 211 case 1: 212 aSNARE_RIM[iNEXTBACK] = aSNARE_RIM[iNEXTBACK] - aUP[iNEXTBACK]; 213 break; 214 215 case 2: 216 switch (iNEXTBACK) { 217 case 2: 218 aHIHAT[iNEXTBACK] = aHIHAT[iNEXTBACK] - aUP[iNEXTBACK]; 219 break; 220 221 default: 222 aHIHAT_CLOSE[iNEXTBACK] = aHIHAT_CLOSE[iNEXTBACK] - aUP[iNEXTBACK]; 223 aHIHAT[iNEXTBACK] = aHIHAT[iNEXTBACK] - aUP[iNEXTBACK]; 224 } 225 break; 226 227 case 3: 228 switch (iNEXTBACK) { 229 case 2: 230 aHIHAT_CLOSE[iNEXTBACK] = aHIHAT_CLOSE[iNEXTBACK] - aUP[iNEXTBACK]; 231 break; 232 233 default: 234 aHIHAT_CLOSE[iNEXTBACK] = aHIHAT_CLOSE[iNEXTBACK] - aUP[iNEXTBACK]; 235 aHIHAT[iNEXTBACK] = aHIHAT[iNEXTBACK] - aUP[iNEXTBACK]; 236 } 237 break; 238 239 case 4: 240 switch (iNEXTBACK) { 241 case 0: 242 aHIHAT_PEDAL[iNEXTBACK] = aHIHAT_PEDAL[iNEXTBACK] - aUP[iNEXTBACK]; 243 break; 244 245 case 2: 246 aHIHAT_PEDAL[iNEXTBACK] = aHIHAT_PEDAL[iNEXTBACK] - aUP[iNEXTBACK]; 247 break; 248 } 249 break; 250 251 case 5: 252 aKICK[iNEXTBACK] = aKICK[iNEXTBACK] - aUP[iNEXTBACK]; 253 break; 254 255 case 6: 256 aSETTING[iNEXTBACK] = aSETTING[iNEXTBACK] - aUP_ADVANCE[iNEXTBACK]; 257 break; 258 } 259 bButtonState = false; 260 delay(30); 261 } 262 263 // Pushbuttons UP; DOWN; NEXT; BACK 264 if (iButton_up == LOW && bButtonState == true && bButtonState_set == true) { 265 iUPDOWN = ++iUPDOWN; 266 bButtonState = false; 267 delay(30); 268 } 269 270 if (iButton_down == LOW && bButtonState == true && bButtonState_set == true) { 271 iUPDOWN = --iUPDOWN; 272 bButtonState = false; 273 delay(30); 274 } 275 276 if (iButton_next == LOW && bButtonState == true && bButtonState_set == true) { 277 iNEXTBACK = ++iNEXTBACK; 278 bButtonState = false; 279 delay(30); 280 } 281 282 if (iButton_back == LOW && bButtonState == true && bButtonState_set == true) { 283 iNEXTBACK = --iNEXTBACK; 284 bButtonState = false; 285 delay(30); 286 } 287 288 if (bButtonState == false && iButton_up == HIGH && iButton_down == HIGH && iButton_next == HIGH && iButton_back == HIGH && iButton_set == HIGH) { 289 // HIGH is defined in Arduino.h Line 40 290 291 switch (iUPDOWN) { 292 293 case 0: 294 lcd.clear(); 295 lcd.print(aINSTRUMENT[iUPDOWN]); 296 lcd.setCursor(0, 1); 297 lcd.print(aSETTING[iNEXTBACK]); 298 lcd.setCursor(12, 1); 299 lcd.print(aSNARE[iNEXTBACK]); 300 break; 301 302 case 1: 303 lcd.clear(); 304 lcd.print(aINSTRUMENT[iUPDOWN]); 305 lcd.setCursor(0, 1); 306 lcd.print(aSETTING[iNEXTBACK]); 307 lcd.setCursor(12, 1); 308 lcd.print(aSNARE_RIM[iNEXTBACK]); 309 break; 310 311 case 2: 312 lcd.clear(); 313 lcd.print(aINSTRUMENT[iUPDOWN]); 314 lcd.setCursor(0, 1); 315 lcd.print(aSETTING[iNEXTBACK]); 316 lcd.setCursor(12, 1); 317 lcd.print(aHIHAT[iNEXTBACK]); 318 break; 319 320 case 3: 321 lcd.clear();lcd.print(aINSTRUMENT[iUPDOWN]); 322 lcd.setCursor(0, 1); 323 lcd.print(aSETTING[iNEXTBACK]); 324 lcd.setCursor(12, 1); 325 lcd.print(aHIHAT_CLOSE[iNEXTBACK]); 326 break; 327 328 case 4: 329 lcd.clear(); 330 lcd.print(aINSTRUMENT[iUPDOWN]); 331 lcd.setCursor(0, 1); 332 lcd.print(aSETTING[iNEXTBACK]); 333 lcd.setCursor(12, 1); 334 lcd.print(aHIHAT_PEDAL[iNEXTBACK]); 335 break; 336 337 case 5: 338 lcd.clear(); 339 lcd.print(aINSTRUMENT[iUPDOWN]); 340 lcd.setCursor(0, 1); 341 lcd.print(aSETTING[iNEXTBACK]); 342 lcd.setCursor(12, 1); 343 lcd.print(aKICK[iNEXTBACK]); 344 break; 345 346 case 6: 347 lcd.clear(); 348 lcd.print(aINSTRUMENT[iUPDOWN]); 349 lcd.setCursor(0, 1); 350 lcd.print(aSETTING_ADVANCE[iNEXTBACK]); 351 lcd.setCursor(12, 1); 352 lcd.print(aSETTING[iNEXTBACK]); 353 break; 354 } 355 356 bButtonState = true; 357 } 358 359 // Instrument Sensors 360 361 // Snare Drum 362 if (iPiezoValue_A0 > aSNARE[0] && bSnareFlag == false) { 363 364 for (int i = 0; i < aSETTING[0]; i++) { 365 int iPeak_A0 = analogRead(A0); 366 int iPeak_A1 = analogRead(A1); 367 delay(1); 368 if (iPeak_A0 > aSNARE[4]) { 369 aSNARE[4] = iPeak_A0; 370 } 371 if (iPeak_A1 > aSNARE_RIM[4]) { 372 aSNARE_RIM[4] = iPeak_A1; 373 } 374 } 375 aSNARE[5] = aSNARE[4]; 376 aSNARE_RIM[5] = aSNARE_RIM[4]; 377 aSNARE[4] = map(aSNARE[4], aSNARE[0], aSNARE[1], 0, 127); 378 aSNARE_RIM[4] = map(aSNARE_RIM[4], aSNARE_RIM[0], aSNARE_RIM[1], 0, 127); 379 aSNARE[4] = (aSNARE[4] * aSNARE[4]) / 127; // Curve setting 380 381 //aSNARE_RIM[4] = (aSNARE_RIM[4] * aSNARE_RIM[4]) / 127; 382 if (aSNARE[4] <= 1) { 383 aSNARE[4] = 1; 384 } 385 if (aSNARE[4] > 127) { 386 aSNARE[4] = 127; 387 } 388 if (aSNARE_RIM[4] <= 0) { 389 aSNARE_RIM[4] = 0; 390 } 391 if (aSNARE_RIM[4] > 127) { 392 aSNARE_RIM[4] = 127; 393 } 394 if (aSNARE_RIM[5] > aSETTING[1]) { 395 MIDI.sendNoteOn(aSNARE_RIM[2], aSNARE_RIM[4], 1); //(note, velocity, channel) 396 MIDI.sendNoteOn(aSNARE_RIM[2], 0, 1); 397 lcd.clear(); 398 lcd.print("SNARE RIM"); 399 lcd.setCursor(0, 1); 400 lcd.print(aSNARE_RIM[4]); 401 bSnareFlag = true; 402 } 403 404 //else if (aSNARE[5] > aSNARE_RIM[5]) 405 else { 406 MIDI.sendNoteOn(aSNARE[2], aSNARE[4], 1); //(note, velocity, channel) 407 MIDI.sendNoteOn(aSNARE[2], 0, 1); 408 lcd.clear(); 409 lcd.print("SNARE HEAD"); 410 lcd.setCursor(0, 1); 411 lcd.print(aSNARE[4]); 412 //lcd.setCursor(10, 1); 413 //lcd.print(aSNARE_RIM[5]); 414 bSnareFlag = true; 415 } 416 } 417 418 // Hi-Hat Cymbal 419 if (iPiezoValue_A2 > aHIHAT[0] && bHihatFlag == false) { 420 for (int i = 0; i < aSETTING[0]; i++) { 421 int iPeak_A2 = analogRead(A2); 422 delay(1); 423 if (iPeak_A2 > aHIHAT[4]) { 424 aHIHAT[4] = iPeak_A2; 425 } 426 } 427 aHIHAT[5] = aHIHAT[4]; 428 aHIHAT[4] = map(aHIHAT[4], aHIHAT[0], aHIHAT[1], 0, 127); 429 aHIHAT[4] = (aHIHAT[4] * aHIHAT[4]) / 127; 430 if (aHIHAT[4] <= 1) { 431 aHIHAT[4] = 1; 432 } 433 if (aHIHAT[4] > 127) { 434 aHIHAT[4] = 127; 435 } 436 if (iPiezoValue_A0 < aHIHAT_PEDAL[0]) { 437 MIDI.sendNoteOn(aHIHAT[2], aHIHAT[4], 1); 438 MIDI.sendNoteOn(aHIHAT[2], 0, 1); 439 lcd.clear(); 440 lcd.print("HIHAT OPEN"); 441 lcd.setCursor(0, 1); 442 lcd.print(aHIHAT[4]); 443 bHihatFlag = true; 444 } 445 else if (iPiezoValue_A0 >= aHIHAT_PEDAL[0]) { 446 MIDI.sendNoteOn(aHIHAT_CLOSE[2], aHIHAT[4], 1); 447 MIDI.sendNoteOn(aHIHAT_CLOSE[2], 0, 1); 448 lcd.clear(); 449 lcd.print("HIHAT CLOSE"); 450 lcd.setCursor(0, 1); 451 lcd.print(aHIHAT[4]); 452 bHihatFlag = true; 453 } 454 } 455 456 // Hi-hat Pedal 457 if (iPiezoValue_A0 > aHIHAT_PEDAL[0] && bPedalFlag == false) { 458 MIDI.sendNoteOn(aHIHAT_PEDAL[2], aSETTING[2], 1); // (note, velocity, channel) 459 MIDI.sendNoteOn(aHIHAT_PEDAL[2], 0, 1); 460 lcd.clear(); 461 lcd.print("HIHAT PEDAL"); 462 lcd.setCursor(0, 1); 463 lcd.print(aSETTING[2]); 464 bPedalFlag = true; 465 } 466 467 // Kick Drum 468 if (iPiezoValue_A3 > aKICK[0] && bKickFlag == false) { 469 for (int i = 0; i < aSETTING[0]; i++) { 470 int iPeak_A3 = analogRead(A3); 471 delay(1); 472 if (iPeak_A3 > aKICK[4]) { 473 aKICK[4] = iPeak_A3; 474 } 475 } 476 477 aKICK[5] = aKICK[4]; 478 aKICK[4] = map(aKICK[4], aKICK[0], aKICK[1], 0, 127); 479 aKICK[4] = (aKICK[4] * aKICK[4]) / 127; 480 if (aKICK[4] <= 1) { 481 aKICK[4] = 1; 482 } 483 if (aKICK[4] > 127) { 484 aKICK[4] = 127; 485 } 486 MIDI.sendNoteOn(aKICK[2], aKICK[4], 1); 487 MIDI.sendNoteOn(aKICK[2], 0, 1); 488 lcd.clear(); 489 lcd.print("KICK"); 490 lcd.setCursor(0, 1); 491 lcd.print(aKICK[4]); 492 bKickFlag = true; 493 } 494 495// --- BEGIN 'Code in Progress' --- // 496// --- I could be wrong, but this is what it appears to be --- and out of curiousity what is purpose of this sequence? -- // 497 498 // I=(A0); // Previous Code 499 // -- DOES iSensorValue_A0 need to be declared as an integer? How does this relate to iPiezoValue_A0? -- // 500 if (iSensorValue_A0 < (aSNARE[5] * (0.01 * aSNARE[3]))) { 501 bSnareFlag = false; 502 } 503 if (iPiezoValue_A0 <= aHIHAT_PEDAL[0] && iPiezoValue_A2 < (aHIHAT[5] * (0.01 * aHIHAT[3])) && bHihatFlag == true) { 504 delay(aSETTING[3]); 505 // iSensorValue_A1 is reading analogRead(A2), but this is aHIHAT_PEDAL (which is analogRead(A2) 506 int iSensorValue_A1 = analogRead(A2); 507 if (iSensorValue_A1 < (aHIHAT[5] * (0.01 * aHIHAT[3]))) { 508 bHihatFlag = false; 509 } 510 } 511 if (iPiezoValue_A0 >= aHIHAT_PEDAL[0] && iPiezoValue_A2 < (aHIHAT[5] *(0.01 * aHIHAT[3])) && bHihatFlag == true) { 512 delay(aSETTING[3]); 513 int iSensorValue_A2 = analogRead(A2); 514 if (iSensorValue_A2 < (aHIHAT[5] * (0.01 * aHIHAT[3]))) { 515 bHihatFlag = false; 516 } 517 } 518 if (iPiezoValue_A3 < (aKICK[5] * (0.01 * aKICK[3])) && bKickFlag == true) { 519 delay(aSETTING[3]); 520 // -- Should declared iSensorValue_A3 be iPiezoValue_A3? iSensorValue_A3 is declared but not used anywhere?? 521 int iSensorValue_A3 = analogRead(A3); 522 if (iPiezoValue_A3 < (aKICK[5] * (0.01 * aKICK[3]))) { 523 bKickFlag = false; 524 } 525 } 526 if (iPiezoValue_A0 <= aHIHAT_PEDAL[0] && bPedalFlag == true) { 527 bPedalFlag = false; 528 } 529 530// --- END 'Code in Progress' --- // 531 }
Hello Drum v2
arduino
Modified: 05/12/2019 by George Brotherston
1/* 2 Drum MIDI Controller 3 Created: 28/06/2017 by Ryo Kosaka as " HELLO DRUM " Ver.1.0 4 Modified: 05/12/2019 by George Brotherston 5*/ 6 7// Library Includes 8 9// #include <Arduino.h> // Arduino Library (automatically included) 10 // LOW (Line 41) 11 // HIGH (Line 40) 12 // INPUT_PULLUP (Line 47) 13 // digitalRead() (Line 177) 14 // analogRead() (Line 178) 15 #include <MIDI.h> // MIDI Library - Version: 4.3.1 16 // includes <midi_Namespace.h> 17 // class MIDI (Line 30) 18 // class method 'begin' (Line 55) 19 #include <LiquidCrystal.h> // LiquidCrystal - Version: 1.0.7 20 // lcd object instantiatied (in Variables section below) from LiquidCrystal class (Line 45) 21 22// Variables - Declare and Initialize 23 24 // Variables - Program 25 boolean bSnareFlag = false; 26 boolean bHihatFlag = false; 27 boolean bKickFlag = false; 28 boolean bPedalFlag = false; 29 boolean bButtonState = true; 30 boolean bButtonState_set = true; 31 int iUPDOWN = 0; 32 int iNEXTBACK = 0; 33 34 // Arrays - Program 35 // InstrumentSensor[6] = {threshold, sensitivity, note, flag, velocity, iPeakValue} 36 // 'iPeakValue' and 'velocity' must be zero for all InstrumentSensor arrays 37 // All 'aHIHAT[]' and 'aHIHAT_CLOSE[]' array elements should have the same value except for 'note' element. 38 int aSNARE[6] = {150, 950, 38, 3, 0, 0}; 39 int aSNARE_RIM[6] = {5, 500, 37, 3 , 0, 0}; 40 int aHIHAT[6] = {100, 800, 46, 1, 0, 0}; 41 int aHIHAT_CLOSE[6] = {100, 800, 42, 1, 0, 0}; 42 int aKICK[6] = {200, 700, 36, 1, 0, 0}; 43 // Instrument_ContinuousController[4] = {scantime, snare/rim, pedalVelocity , masktime} 44 int aHIHAT_PEDAL[4] = {600, 0, 44, 0}; 45 // InstrumentSensor_ParameterValue[4] = {threshold, sensitivity, note, flag} 46 int aSETTING[4] = {4, 500 ,100 ,1}; 47 48 // Libraries 49 // LiquidCrystal.h 50 // Constants (already defined in Library, still in scope? If not then define below) 51 // const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 52 // lcd object instantiatiated from LiquidCrystal class (LiquidCrystal.h Line 45) 53 LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // Associate LCD interface pins to associated Arduino pin number 54 // MIDI.h 55 // Initialize the library 56 MIDI_CREATE_DEFAULT_INSTANCE(); 57 58// Program Code 59 60 // Program Execution - Initial (program setup) 61 62 void setup() { 63 MIDI.begin(10); // begin (MIDI.h Line 55) 64 lcd.begin(16, 2); // begin (LiquidCrystal.h Line 62) 65 lcd.print("INITIALIZING..."); // print (LiquidCrystal.h Line 45) 66 lcd.setCursor(0, 1); // setCursor (LiquidCrystal.h Line 82) 67 lcd.print("DRUM MIDI CONTROLLER"); 68 pinMode(6, INPUT_PULLUP); // pinMode (Arduino.h Line 175); INPUT_PULLUP (Arduino.h Line 47) 69 pinMode(7, INPUT_PULLUP); 70 pinMode(8, INPUT_PULLUP); 71 pinMode(9, INPUT_PULLUP); 72 pinMode(10, INPUT_PULLUP); 73 } 74 75 // Program Execution - Steadystate (continuous loop until power is lost) 76 77 void loop() { 78 // Drum MIDI Controller Circuit 79 // Declare and Initialize Variables 80 81 int iButton_set = digitalRead(6); // Set Button // digitalRead() (Arduino.h Line 177) 82 int iButton_up = digitalRead(7); // Up Button 83 int iButton_down = digitalRead(8); // Down Button 84 int iButton_next = digitalRead(9); // Next Button 85 int iButton_back = digitalRead(10); // Back Button 86 int iPiezoValue_A0 = analogRead(A0); // Piezo - Snare Head // analogRead() (Arduino.h Line 178) 87 int iPiezoValue_A1 = analogRead(A1); // Piezo - Snare Rim 88 int iPiezoValue_A2 = analogRead(A2); // Hi-hat 89 int iPiezoValue_A3 = analogRead(A3); // Kick Drum 90 int iFSRValue_A4 = analogRead(A4); // Hi-hat Pedal 91 92 // Edit Mode 93 94 int aUP[4] = {5, 50, 1,1}; // {threshold, sensitivity, note, flag} 95 int aUP_ADVANCE[4] = {1, 50, 1,1}; // {scantime, rim/head, pedal velocity, masktime} 96 97 // Note: aINSTRUMENT[] array was not declared in 'Arrays' above 98 char* aINSTRUMENT[] = { 99 "SNARE HEAD", "SNARE RIM", "HIHAT OPEN", "HIHAT CLOSE", "HIHAT PEDAL", "KICK", "ADVANCED SETTING" 100 }; 101 102 // Note: aSETTING[] array WAS declared in 'Arrays' above 103 char* aSETTING[] = { 104 "THRESHOLD", "SENSITIVITY", "NOTE", "FLAG" 105 }; 106 107 // Note: aSETTING_ADVANCE[] was not declared in 'Arrays' above 108 char* aSETTING_ADVANCE[] = { 109 "SCAN TIME", "HEAD / RIM ","PEDAL VELO", "MASK TIME" 110 }; 111 112 if (iUPDOWN < 0) { 113 iUPDOWN = 6; 114 } 115 116 if (iUPDOWN > 6) { 117 iUPDOWN = 0; 118 } 119 120 if (iNEXTBACK < 0) { 121 iNEXTBACK = 3; 122 } 123 124 if (iNEXTBACK > 3) { 125 iNEXTBACK = 0; 126 } 127 128 // Pushbutton EDIT 129 // LOW (Arduino.h Line 41) 130 if (iButton_set == LOW && bButtonState == true && bButtonState_set == true) { 131 lcd.clear(); 132 lcd.print("EDIT"); 133 bButtonState = false; 134 bButtonState_set = false; 135 delay(500); 136 } 137 138 if (iButton_set == LOW && bButtonState == true && bButtonState_set == false) { 139 lcd.clear(); 140 lcd.print("EDIT DONE"); 141 bButtonState = false; 142 bButtonState_set = true; 143 delay(500); 144 } 145 146 if (iButton_up == LOW && bButtonState == true && bButtonState_set == false) { 147 switch (iUPDOWN) { 148 case 0: 149 aSNARE[iNEXTBACK] = aSNARE[iNEXTBACK] + aUP[iNEXTBACK]; 150 break; 151 152 case 1: 153 aSNARE_RIM[iNEXTBACK] = aSNARE_RIM[iNEXTBACK] + aUP[iNEXTBACK]; 154 break; 155 156 case 2: 157 switch (iNEXTBACK) { 158 case 2: 159 aHIHAT[iNEXTBACK] = aHIHAT[iNEXTBACK] + aUP[iNEXTBACK]; 160 break; 161 162 default: 163 aHIHAT_CLOSE[iNEXTBACK] = aHIHAT_CLOSE[iNEXTBACK] + aUP[iNEXTBACK]; 164 aHIHAT[iNEXTBACK] = aHIHAT[iNEXTBACK] + aUP[iNEXTBACK]; 165 } 166 break; 167 168 case 3: 169 switch (iNEXTBACK) { 170 case 2: 171 aHIHAT_CLOSE[iNEXTBACK] = aHIHAT_CLOSE[iNEXTBACK] + aUP[iNEXTBACK]; 172 break; 173 174 default: 175 aHIHAT_CLOSE[iNEXTBACK] = aHIHAT_CLOSE[iNEXTBACK] + aUP[iNEXTBACK]; 176 aHIHAT[iNEXTBACK] = aHIHAT[iNEXTBACK] + aUP[iNEXTBACK]; 177 } 178 break; 179 180 case 4: 181 switch (iNEXTBACK) { 182 case 0: 183 aHIHAT_PEDAL[iNEXTBACK] = aHIHAT_PEDAL[iNEXTBACK] + aUP[iNEXTBACK]; 184 break; 185 186 case 2: 187 aHIHAT_PEDAL[iNEXTBACK] = aHIHAT_PEDAL[iNEXTBACK] + aUP[iNEXTBACK]; 188 break; 189 } 190 break; 191 192 case 5: 193 aKICK[iNEXTBACK] = aKICK[iNEXTBACK] + aUP[iNEXTBACK]; 194 break; 195 196 case 6: 197 aSETTING[iNEXTBACK] = aSETTING[iNEXTBACK] + aUP_ADVANCE[iNEXTBACK]; 198 break; 199 } 200 bButtonState = false; 201 delay(30); 202 } 203 204 if (iButton_down == LOW && bButtonState == true && bButtonState_set == false) { 205 206 switch (iUPDOWN) { 207 case 0: 208 aSNARE[iNEXTBACK] = aSNARE[iNEXTBACK] - aUP[iNEXTBACK]; 209 break; 210 211 case 1: 212 aSNARE_RIM[iNEXTBACK] = aSNARE_RIM[iNEXTBACK] - aUP[iNEXTBACK]; 213 break; 214 215 case 2: 216 switch (iNEXTBACK) { 217 case 2: 218 aHIHAT[iNEXTBACK] = aHIHAT[iNEXTBACK] - aUP[iNEXTBACK]; 219 break; 220 221 default: 222 aHIHAT_CLOSE[iNEXTBACK] = aHIHAT_CLOSE[iNEXTBACK] - aUP[iNEXTBACK]; 223 aHIHAT[iNEXTBACK] = aHIHAT[iNEXTBACK] - aUP[iNEXTBACK]; 224 } 225 break; 226 227 case 3: 228 switch (iNEXTBACK) { 229 case 2: 230 aHIHAT_CLOSE[iNEXTBACK] = aHIHAT_CLOSE[iNEXTBACK] - aUP[iNEXTBACK]; 231 break; 232 233 default: 234 aHIHAT_CLOSE[iNEXTBACK] = aHIHAT_CLOSE[iNEXTBACK] - aUP[iNEXTBACK]; 235 aHIHAT[iNEXTBACK] = aHIHAT[iNEXTBACK] - aUP[iNEXTBACK]; 236 } 237 break; 238 239 case 4: 240 switch (iNEXTBACK) { 241 case 0: 242 aHIHAT_PEDAL[iNEXTBACK] = aHIHAT_PEDAL[iNEXTBACK] - aUP[iNEXTBACK]; 243 break; 244 245 case 2: 246 aHIHAT_PEDAL[iNEXTBACK] = aHIHAT_PEDAL[iNEXTBACK] - aUP[iNEXTBACK]; 247 break; 248 } 249 break; 250 251 case 5: 252 aKICK[iNEXTBACK] = aKICK[iNEXTBACK] - aUP[iNEXTBACK]; 253 break; 254 255 case 6: 256 aSETTING[iNEXTBACK] = aSETTING[iNEXTBACK] - aUP_ADVANCE[iNEXTBACK]; 257 break; 258 } 259 bButtonState = false; 260 delay(30); 261 } 262 263 // Pushbuttons UP; DOWN; NEXT; BACK 264 if (iButton_up == LOW && bButtonState == true && bButtonState_set == true) { 265 iUPDOWN = ++iUPDOWN; 266 bButtonState = false; 267 delay(30); 268 } 269 270 if (iButton_down == LOW && bButtonState == true && bButtonState_set == true) { 271 iUPDOWN = --iUPDOWN; 272 bButtonState = false; 273 delay(30); 274 } 275 276 if (iButton_next == LOW && bButtonState == true && bButtonState_set == true) { 277 iNEXTBACK = ++iNEXTBACK; 278 bButtonState = false; 279 delay(30); 280 } 281 282 if (iButton_back == LOW && bButtonState == true && bButtonState_set == true) { 283 iNEXTBACK = --iNEXTBACK; 284 bButtonState = false; 285 delay(30); 286 } 287 288 if (bButtonState == false && iButton_up == HIGH && iButton_down == HIGH && iButton_next == HIGH && iButton_back == HIGH && iButton_set == HIGH) { 289 // HIGH is defined in Arduino.h Line 40 290 291 switch (iUPDOWN) { 292 293 case 0: 294 lcd.clear(); 295 lcd.print(aINSTRUMENT[iUPDOWN]); 296 lcd.setCursor(0, 1); 297 lcd.print(aSETTING[iNEXTBACK]); 298 lcd.setCursor(12, 1); 299 lcd.print(aSNARE[iNEXTBACK]); 300 break; 301 302 case 1: 303 lcd.clear(); 304 lcd.print(aINSTRUMENT[iUPDOWN]); 305 lcd.setCursor(0, 1); 306 lcd.print(aSETTING[iNEXTBACK]); 307 lcd.setCursor(12, 1); 308 lcd.print(aSNARE_RIM[iNEXTBACK]); 309 break; 310 311 case 2: 312 lcd.clear(); 313 lcd.print(aINSTRUMENT[iUPDOWN]); 314 lcd.setCursor(0, 1); 315 lcd.print(aSETTING[iNEXTBACK]); 316 lcd.setCursor(12, 1); 317 lcd.print(aHIHAT[iNEXTBACK]); 318 break; 319 320 case 3: 321 lcd.clear();lcd.print(aINSTRUMENT[iUPDOWN]); 322 lcd.setCursor(0, 1); 323 lcd.print(aSETTING[iNEXTBACK]); 324 lcd.setCursor(12, 1); 325 lcd.print(aHIHAT_CLOSE[iNEXTBACK]); 326 break; 327 328 case 4: 329 lcd.clear(); 330 lcd.print(aINSTRUMENT[iUPDOWN]); 331 lcd.setCursor(0, 1); 332 lcd.print(aSETTING[iNEXTBACK]); 333 lcd.setCursor(12, 1); 334 lcd.print(aHIHAT_PEDAL[iNEXTBACK]); 335 break; 336 337 case 5: 338 lcd.clear(); 339 lcd.print(aINSTRUMENT[iUPDOWN]); 340 lcd.setCursor(0, 1); 341 lcd.print(aSETTING[iNEXTBACK]); 342 lcd.setCursor(12, 1); 343 lcd.print(aKICK[iNEXTBACK]); 344 break; 345 346 case 6: 347 lcd.clear(); 348 lcd.print(aINSTRUMENT[iUPDOWN]); 349 lcd.setCursor(0, 1); 350 lcd.print(aSETTING_ADVANCE[iNEXTBACK]); 351 lcd.setCursor(12, 1); 352 lcd.print(aSETTING[iNEXTBACK]); 353 break; 354 } 355 356 bButtonState = true; 357 } 358 359 // Instrument Sensors 360 361 // Snare Drum 362 if (iPiezoValue_A0 > aSNARE[0] && bSnareFlag == false) { 363 364 for (int i = 0; i < aSETTING[0]; i++) { 365 int iPeak_A0 = analogRead(A0); 366 int iPeak_A1 = analogRead(A1); 367 delay(1); 368 if (iPeak_A0 > aSNARE[4]) { 369 aSNARE[4] = iPeak_A0; 370 } 371 if (iPeak_A1 > aSNARE_RIM[4]) { 372 aSNARE_RIM[4] = iPeak_A1; 373 } 374 } 375 aSNARE[5] = aSNARE[4]; 376 aSNARE_RIM[5] = aSNARE_RIM[4]; 377 aSNARE[4] = map(aSNARE[4], aSNARE[0], aSNARE[1], 0, 127); 378 aSNARE_RIM[4] = map(aSNARE_RIM[4], aSNARE_RIM[0], aSNARE_RIM[1], 0, 127); 379 aSNARE[4] = (aSNARE[4] * aSNARE[4]) / 127; // Curve setting 380 381 //aSNARE_RIM[4] = (aSNARE_RIM[4] * aSNARE_RIM[4]) / 127; 382 if (aSNARE[4] <= 1) { 383 aSNARE[4] = 1; 384 } 385 if (aSNARE[4] > 127) { 386 aSNARE[4] = 127; 387 } 388 if (aSNARE_RIM[4] <= 0) { 389 aSNARE_RIM[4] = 0; 390 } 391 if (aSNARE_RIM[4] > 127) { 392 aSNARE_RIM[4] = 127; 393 } 394 if (aSNARE_RIM[5] > aSETTING[1]) { 395 MIDI.sendNoteOn(aSNARE_RIM[2], aSNARE_RIM[4], 1); //(note, velocity, channel) 396 MIDI.sendNoteOn(aSNARE_RIM[2], 0, 1); 397 lcd.clear(); 398 lcd.print("SNARE RIM"); 399 lcd.setCursor(0, 1); 400 lcd.print(aSNARE_RIM[4]); 401 bSnareFlag = true; 402 } 403 404 //else if (aSNARE[5] > aSNARE_RIM[5]) 405 else { 406 MIDI.sendNoteOn(aSNARE[2], aSNARE[4], 1); //(note, velocity, channel) 407 MIDI.sendNoteOn(aSNARE[2], 0, 1); 408 lcd.clear(); 409 lcd.print("SNARE HEAD"); 410 lcd.setCursor(0, 1); 411 lcd.print(aSNARE[4]); 412 //lcd.setCursor(10, 1); 413 //lcd.print(aSNARE_RIM[5]); 414 bSnareFlag = true; 415 } 416 } 417 418 // Hi-Hat Cymbal 419 if (iPiezoValue_A2 > aHIHAT[0] && bHihatFlag == false) { 420 for (int i = 0; i < aSETTING[0]; i++) { 421 int iPeak_A2 = analogRead(A2); 422 delay(1); 423 if (iPeak_A2 > aHIHAT[4]) { 424 aHIHAT[4] = iPeak_A2; 425 } 426 } 427 aHIHAT[5] = aHIHAT[4]; 428 aHIHAT[4] = map(aHIHAT[4], aHIHAT[0], aHIHAT[1], 0, 127); 429 aHIHAT[4] = (aHIHAT[4] * aHIHAT[4]) / 127; 430 if (aHIHAT[4] <= 1) { 431 aHIHAT[4] = 1; 432 } 433 if (aHIHAT[4] > 127) { 434 aHIHAT[4] = 127; 435 } 436 if (iPiezoValue_A0 < aHIHAT_PEDAL[0]) { 437 MIDI.sendNoteOn(aHIHAT[2], aHIHAT[4], 1); 438 MIDI.sendNoteOn(aHIHAT[2], 0, 1); 439 lcd.clear(); 440 lcd.print("HIHAT OPEN"); 441 lcd.setCursor(0, 1); 442 lcd.print(aHIHAT[4]); 443 bHihatFlag = true; 444 } 445 else if (iPiezoValue_A0 >= aHIHAT_PEDAL[0]) { 446 MIDI.sendNoteOn(aHIHAT_CLOSE[2], aHIHAT[4], 1); 447 MIDI.sendNoteOn(aHIHAT_CLOSE[2], 0, 1); 448 lcd.clear(); 449 lcd.print("HIHAT CLOSE"); 450 lcd.setCursor(0, 1); 451 lcd.print(aHIHAT[4]); 452 bHihatFlag = true; 453 } 454 } 455 456 // Hi-hat Pedal 457 if (iPiezoValue_A0 > aHIHAT_PEDAL[0] && bPedalFlag == false) { 458 MIDI.sendNoteOn(aHIHAT_PEDAL[2], aSETTING[2], 1); // (note, velocity, channel) 459 MIDI.sendNoteOn(aHIHAT_PEDAL[2], 0, 1); 460 lcd.clear(); 461 lcd.print("HIHAT PEDAL"); 462 lcd.setCursor(0, 1); 463 lcd.print(aSETTING[2]); 464 bPedalFlag = true; 465 } 466 467 // Kick Drum 468 if (iPiezoValue_A3 > aKICK[0] && bKickFlag == false) { 469 for (int i = 0; i < aSETTING[0]; i++) { 470 int iPeak_A3 = analogRead(A3); 471 delay(1); 472 if (iPeak_A3 > aKICK[4]) { 473 aKICK[4] = iPeak_A3; 474 } 475 } 476 477 aKICK[5] = aKICK[4]; 478 aKICK[4] = map(aKICK[4], aKICK[0], aKICK[1], 0, 127); 479 aKICK[4] = (aKICK[4] * aKICK[4]) / 127; 480 if (aKICK[4] <= 1) { 481 aKICK[4] = 1; 482 } 483 if (aKICK[4] > 127) { 484 aKICK[4] = 127; 485 } 486 MIDI.sendNoteOn(aKICK[2], aKICK[4], 1); 487 MIDI.sendNoteOn(aKICK[2], 0, 1); 488 lcd.clear(); 489 lcd.print("KICK"); 490 lcd.setCursor(0, 1); 491 lcd.print(aKICK[4]); 492 bKickFlag = true; 493 } 494 495// --- BEGIN 'Code in Progress' --- // 496// --- I could be wrong, but this is what it appears to be --- and out of curiousity what is purpose of this sequence? -- // 497 498 // I=(A0); // Previous Code 499 // -- DOES iSensorValue_A0 need to be declared as an integer? How does this relate to iPiezoValue_A0? -- // 500 if (iSensorValue_A0 < (aSNARE[5] * (0.01 * aSNARE[3]))) { 501 bSnareFlag = false; 502 } 503 if (iPiezoValue_A0 <= aHIHAT_PEDAL[0] && iPiezoValue_A2 < (aHIHAT[5] * (0.01 * aHIHAT[3])) && bHihatFlag == true) { 504 delay(aSETTING[3]); 505 // iSensorValue_A1 is reading analogRead(A2), but this is aHIHAT_PEDAL (which is analogRead(A2) 506 int iSensorValue_A1 = analogRead(A2); 507 if (iSensorValue_A1 < (aHIHAT[5] * (0.01 * aHIHAT[3]))) { 508 bHihatFlag = false; 509 } 510 } 511 if (iPiezoValue_A0 >= aHIHAT_PEDAL[0] && iPiezoValue_A2 < (aHIHAT[5] *(0.01 * aHIHAT[3])) && bHihatFlag == true) { 512 delay(aSETTING[3]); 513 int iSensorValue_A2 = analogRead(A2); 514 if (iSensorValue_A2 < (aHIHAT[5] * (0.01 * aHIHAT[3]))) { 515 bHihatFlag = false; 516 } 517 } 518 if (iPiezoValue_A3 < (aKICK[5] * (0.01 * aKICK[3])) && bKickFlag == true) { 519 delay(aSETTING[3]); 520 // -- Should declared iSensorValue_A3 be iPiezoValue_A3? iSensorValue_A3 is declared but not used anywhere?? 521 int iSensorValue_A3 = analogRead(A3); 522 if (iPiezoValue_A3 < (aKICK[5] * (0.01 * aKICK[3]))) { 523 bKickFlag = false; 524 } 525 } 526 if (iPiezoValue_A0 <= aHIHAT_PEDAL[0] && bPedalFlag == true) { 527 bPedalFlag = false; 528 } 529 530// --- END 'Code in Progress' --- // 531 }
Downloadable files
circuit_x5tIBQ5SLw.png
circuit_x5tIBQ5SLw.png
circuit_nZotR7rJMM.fzz
circuit_nZotR7rJMM.fzz
circuit_nZotR7rJMM.fzz
circuit_nZotR7rJMM.fzz
circuit_x5tIBQ5SLw.png
circuit_x5tIBQ5SLw.png
Comments
Only logged in users can leave comments
ryokosaka
0 Followers
•0 Projects
Table of contents
Intro
40
0