├── Arduino Midi Clocker Schematic.jpg ├── ArduinoMidiClocker_FINAL ├── ArduinoMidiClocker1.0 └── ArduinoMidiClocker_1.1.1.ino ├── IMG_4367.jpg ├── Pictures MIDI Clocker ├── 1.jpg └── 2.jpg └── README.md /Arduino Midi Clocker Schematic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luislutz/Arduino-MIDI-Clocker/13f5c3bfaf783b24d4901429fb9d86d53e4d84d1/Arduino Midi Clocker Schematic.jpg -------------------------------------------------------------------------------- /ArduinoMidiClocker_FINAL/ArduinoMidiClocker1.0: -------------------------------------------------------------------------------- 1 | #include "MIDIUSB.h" 2 | #include 3 | #include 4 | 5 | 6 | 7 | 8 | //HARDWAR PIN NUMBERS: 9 | 10 | #define CLOCK_1 1 //CLOCK LEDS AND OUTPUTS 11 | #define CLOCK_2 0 12 | #define CLOCK_3 2 13 | #define CLOCK_4 3 14 | 15 | #define RESET_1 4 //RESET LEDS 16 | #define RESET_2 5 17 | #define RESET_3 6 18 | #define RESET_4 7 19 | 20 | #define DELAY_1 A3 //POTIS 21 | #define DELAY_2 A2 22 | #define DELAY_3 A1 23 | #define DELAY_4 A0 24 | 25 | 26 | 27 | 28 | #define DELAY 8 29 | #define SUBDIV 9 30 | #define RESET 10 31 | 32 | #define DEL_RNG 50 // Define Delay Range in ms 33 | 34 | #define DIV_RNG 7 // Define Clock Division Range: 0 = 2Pulse/1Sixteenth1 = 1 Pulse/Sixteenth, 2 = 1Pulse/Eights, 3 = 1 Pulse/1Quater, 4 = 1Pulse/2Quater, 5 = 1Pulse/1Bar, 6 = 1Pulse/2Bars, 7 = None 35 | 36 | #define RES_RNG 7 // Define Reset Division Rannge: 0 = 2Pulse/1Sixteenth1 = 1 Pulse/Sixteenth, 2 = 1Pulse/Eights, 3 = 1 Pulse/1Quater, 4 = 1Pulse/2Quater, 5 = 1Pulse/1Bar, 6 = 1Pulse/2Bars, 7 = None 37 | 38 | int SUBDIVISION[] = {255,255,255,255,240,216,192,168,144,120,96,72,60,54,48,42,30,27,24,21,18,15,12,9,8,7,6,5,4,3,3,3}; // Mapping Array for Fine Division 39 | 40 | #define save_time_delay 30000 // Save timer to Spare on EEPROM Cycles 41 | #define save_time_division 30000 42 | #define save_time_reset 30000 43 | 44 | #define Pot_thr 63 // Resolution for pot movement detection (Range: ~5 - 255) 45 | 46 | #define Pulse_Length 20 // Output Pulse Duration in ms 47 | 48 | 49 | 50 | 51 | 52 | int D1 = EEPROM.read(4); //Read Stored Values only once when powered up 53 | int D2 = EEPROM.read(5); 54 | int D3 = EEPROM.read(6); 55 | int D4 = EEPROM.read(7); 56 | 57 | int D1_Save = EEPROM.read(16); 58 | int D2_Save = EEPROM.read(17); 59 | int D3_Save = EEPROM.read(18); 60 | int D4_Save = EEPROM.read(19); 61 | 62 | 63 | int V1 = EEPROM.read(8); 64 | int V2 = EEPROM.read(9); 65 | int V3 = EEPROM.read(10); 66 | int V4 = EEPROM.read(11); 67 | 68 | int V1_Save = EEPROM.read(12); 69 | int V2_Save = EEPROM.read(13); 70 | int V3_Save = EEPROM.read(14); 71 | int V4_Save = EEPROM.read(15); 72 | 73 | int V1_Save_FINE = EEPROM.read(20); 74 | int V2_Save_FINE = EEPROM.read(21); 75 | int V3_Save_FINE = EEPROM.read(22); 76 | int V4_Save_FINE = EEPROM.read(23); 77 | 78 | int R1 = EEPROM.read(24); 79 | int R2 = EEPROM.read(25); 80 | int R3 = EEPROM.read(26); 81 | int R4 = EEPROM.read(27); 82 | 83 | int R1_Save = EEPROM.read(28); 84 | int R2_Save = EEPROM.read(29); 85 | int R3_Save = EEPROM.read(30); 86 | int R4_Save = EEPROM.read(31); 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | // SETUP 96 | 97 | 98 | 99 | 100 | void setup() 101 | { 102 | pinMode(CLOCK_1, OUTPUT); // Pin Configuration 103 | pinMode(CLOCK_2, OUTPUT); 104 | pinMode(CLOCK_3, OUTPUT); 105 | pinMode(CLOCK_4, OUTPUT); 106 | 107 | pinMode(RESET_1, OUTPUT); 108 | pinMode(RESET_2, OUTPUT); 109 | pinMode(RESET_3, OUTPUT); 110 | pinMode(RESET_4, OUTPUT); 111 | 112 | 113 | pinMode(DELAY_1, INPUT); 114 | pinMode(DELAY_2, INPUT); 115 | pinMode(DELAY_3, INPUT); 116 | pinMode(DELAY_4, INPUT); 117 | 118 | pinMode(DELAY, INPUT_PULLUP); 119 | pinMode(SUBDIV, INPUT_PULLUP); 120 | pinMode(RESET, INPUT_PULLUP); 121 | 122 | 123 | digitalWrite(CLOCK_1, LOW); // Put Outputs Low 124 | digitalWrite(CLOCK_2, LOW); 125 | digitalWrite(CLOCK_3, LOW); 126 | digitalWrite(CLOCK_4, LOW); 127 | 128 | digitalWrite(RESET_1, LOW); 129 | digitalWrite(RESET_2, LOW); 130 | digitalWrite(RESET_3, LOW); 131 | digitalWrite(RESET_4, LOW); 132 | 133 | 134 | SPI.begin(); 135 | 136 | Serial.begin(115200); 137 | 138 | 139 | } 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | //LOOP 153 | 154 | 155 | 156 | 157 | void loop() 158 | { 159 | static unsigned long clock_timer_1 = 0, clock_timeout_1 = 0; // Clock Timers 160 | static unsigned long clock_timer_2 = 0, clock_timeout_2 = 0; 161 | static unsigned long clock_timer_3 = 0, clock_timeout_3 = 0; 162 | static unsigned long clock_timer_4 = 0, clock_timeout_4 = 0; 163 | 164 | static unsigned long reset_timer_1 = 0, reset_timeout_1 = 0; // Reset Timers 165 | static unsigned long reset_timer_2 = 0, reset_timeout_2 = 0; 166 | static unsigned long reset_timer_3 = 0, reset_timeout_3 = 0; 167 | static unsigned long reset_timer_4 = 0, reset_timeout_4 = 0; 168 | 169 | 170 | static unsigned long save_timer_delay_1 = 0; // Timer for delaying Saving Time 171 | static unsigned long save_timer_delay_2 = 0; 172 | static unsigned long save_timer_delay_3 = 0; 173 | static unsigned long save_timer_delay_4 = 0; 174 | 175 | static unsigned long save_timer_division_1 = 0; 176 | static unsigned long save_timer_division_2 = 0; 177 | static unsigned long save_timer_division_3 = 0; 178 | static unsigned long save_timer_division_4 = 0; 179 | 180 | 181 | static unsigned long save_timer_division_5 = 0; 182 | static unsigned long save_timer_division_6 = 0; 183 | static unsigned long save_timer_division_7 = 0; 184 | static unsigned long save_timer_division_8 = 0; 185 | 186 | static unsigned long save_timer_reset_1 = 0; 187 | static unsigned long save_timer_reset_2 = 0; 188 | static unsigned long save_timer_reset_3 = 0; 189 | static unsigned long save_timer_reset_4 = 0; 190 | 191 | 192 | 193 | 194 | static unsigned int clock_count_1 = 0; //Clock Counters 195 | static unsigned int clock_count_2 = 0; 196 | static unsigned int clock_count_3 = 0; 197 | static unsigned int clock_count_4 = 0; 198 | 199 | static unsigned int reset_count_1 = 0; //Reset Counters 200 | static unsigned int reset_count_2 = 0; 201 | static unsigned int reset_count_3 = 0; 202 | static unsigned int reset_count_4 = 0; 203 | 204 | static bool MCS_1 = false; // Master Clock States (undelayed Clock State) 205 | static bool MCS_2 = false; 206 | static bool MCS_3 = false; 207 | static bool MCS_4 = false; 208 | 209 | static bool MCS_5 = false; // Master Reset States (undelayed Reset State) 210 | static bool MCS_6 = false; 211 | static bool MCS_7 = false; 212 | static bool MCS_8 = false; 213 | 214 | 215 | static bool Check_1 = false; // Check bools for Save time delay 216 | static bool Check_2 = false; 217 | static bool Check_3 = false; 218 | static bool Check_4 = false; 219 | static bool Check_5 = false; 220 | static bool Check_6 = false; 221 | static bool Check_7 = false; 222 | static bool Check_8 = false; 223 | static bool Check_9 = false; 224 | static bool Check_10 = false; 225 | static bool Check_11 = false; 226 | static bool Check_12 = false; 227 | static bool Check_13 = false; 228 | static bool Check_14 = false; 229 | static bool Check_15 = false; 230 | static bool Check_16 = false; 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | bool D = !digitalRead(DELAY); //Switches Read in 239 | bool S = !digitalRead(SUBDIV); 240 | bool R = !digitalRead(RESET); 241 | 242 | 243 | 244 | 245 | if (D == true) { 246 | 247 | 248 | if (D1_Save != map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr)) { 249 | 250 | D1 = int(map(analogRead(DELAY_1), 0, 1023, 0, DEL_RNG)); // Delay Wert Auslesen der Potentiometer 251 | save_timer_delay_1 = millis(); 252 | Check_1 = true; 253 | V1_Save = map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr); 254 | V1_Save_FINE = map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr); 255 | R1_Save = map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr); 256 | } 257 | 258 | 259 | if (D2_Save != map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr)) { 260 | 261 | D2 = int(map(analogRead(DELAY_2), 0, 1023, 0, DEL_RNG)); 262 | save_timer_delay_2 = millis(); 263 | Check_2 = true; 264 | V2_Save = map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr); 265 | V2_Save_FINE = map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr); 266 | R2_Save = map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr); 267 | 268 | } 269 | 270 | 271 | if (D3_Save != map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr)) { 272 | 273 | D3 = int(map(analogRead(DELAY_3), 0, 1023, 0, DEL_RNG)); 274 | save_timer_delay_3 = millis(); 275 | Check_3 = true; 276 | V3_Save = map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr); 277 | V3_Save_FINE = map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr); 278 | R3_Save = map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr); 279 | } 280 | 281 | 282 | if (D4_Save != map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr)) { 283 | 284 | D4 = int(map(analogRead(DELAY_4), 0, 1023, 0, DEL_RNG)); 285 | save_timer_delay_4 = millis(); 286 | Check_4 = true; 287 | V4_Save = map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr); 288 | V4_Save_FINE = map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr); 289 | R4_Save = map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr); 290 | } 291 | } 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | else if (R == true) { 300 | 301 | if (R1_Save != map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr)) { 302 | 303 | R1 = 3 * round(pow(2, int(map(analogRead(DELAY_1), 0, 1023, RES_RNG, 0)))); // Reset Wert Auslesen der Potentiometer 304 | save_timer_reset_1 = millis(); 305 | Check_13 = true; 306 | V1_Save = map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr); 307 | V1_Save_FINE = map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr); 308 | D1_Save = map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr); 309 | } 310 | 311 | if (R2_Save != map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr)) { 312 | 313 | R2 = 3 * round(pow(2, int(map(analogRead(DELAY_2), 0, 1023, RES_RNG, 0)))); 314 | save_timer_reset_2 = millis(); 315 | Check_14 = true; 316 | V2_Save = map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr); 317 | V2_Save_FINE = map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr); 318 | D2_Save = map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr); 319 | } 320 | 321 | if (R3_Save != map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr)) { 322 | 323 | R3 = 3 * round(pow(2, int(map(analogRead(DELAY_3), 0, 1023, RES_RNG, 0)))); 324 | save_timer_reset_3 = millis(); 325 | Check_15 = true; 326 | V3_Save = map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr); 327 | V3_Save_FINE = map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr); 328 | D3_Save = map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr); 329 | } 330 | 331 | if (R4_Save != map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr)) { 332 | 333 | R4 = 3 * round(pow(2, int(map(analogRead(DELAY_4), 0, 1023, RES_RNG, 0)))); 334 | save_timer_reset_4 = millis(); 335 | Check_16 = true; 336 | V4_Save = map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr); 337 | V4_Save_FINE = map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr); 338 | D4_Save = map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr); 339 | } 340 | 341 | } 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | else if (S == false) { 351 | 352 | if (V1_Save != map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr)) { 353 | 354 | V1 = 3 * round(pow(2, int(map(analogRead(DELAY_1), 0, 1023, DIV_RNG, 0)))); // Division Wert Auslesen der Potentiometer 355 | save_timer_division_1 = millis(); 356 | Check_5 = true; 357 | D1_Save = map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr); 358 | V1_Save_FINE = map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr); 359 | R1_Save = map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr); 360 | } 361 | 362 | if (V2_Save != map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr)) { 363 | 364 | V2 = 3 * round(pow(2, int(map(analogRead(DELAY_2), 0, 1023, DIV_RNG, 0)))); 365 | save_timer_division_2 = millis(); 366 | Check_6 = true; 367 | D2_Save = map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr); 368 | V2_Save_FINE = map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr); 369 | R2_Save = map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr); 370 | } 371 | 372 | if (V3_Save != map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr)) { 373 | 374 | V3 = 3 * round(pow(2, int(map(analogRead(DELAY_3), 0, 1023, DIV_RNG, 0)))); 375 | save_timer_division_3 = millis(); 376 | Check_7 = true; 377 | D3_Save = map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr); 378 | V3_Save_FINE = map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr); 379 | R3_Save = map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr); 380 | } 381 | 382 | if (V4_Save != map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr)) { 383 | 384 | V4 = 3 * round(pow(2, int(map(analogRead(DELAY_4), 0, 1023, DIV_RNG, 0)))); 385 | save_timer_division_4 = millis(); 386 | Check_8 = true; 387 | D4_Save = map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr); 388 | V4_Save_FINE = map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr); 389 | R4_Save = map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr); 390 | 391 | } 392 | 393 | 394 | 395 | 396 | } 397 | 398 | 399 | 400 | 401 | 402 | else { 403 | 404 | if (V1_Save_FINE != map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr)) { 405 | 406 | V1 = SUBDIVISION[round(analogRead(DELAY_1)/32)]; // Fine Division Wert Auslesen der Potentiometer 407 | save_timer_division_5 = millis(); 408 | Check_9 = true; 409 | D1_Save = map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr); 410 | V1_Save = map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr); 411 | R1_Save = map(analogRead(DELAY_1), 0, 1023, 0, Pot_thr); 412 | 413 | } 414 | 415 | if (V2_Save_FINE != map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr)) { 416 | 417 | V2 = SUBDIVISION[round(analogRead(DELAY_2)/32)]; 418 | save_timer_division_6 = millis(); 419 | Check_10 = true; 420 | D2_Save = map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr); 421 | V2_Save = map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr); 422 | R2_Save = map(analogRead(DELAY_2), 0, 1023, 0, Pot_thr); 423 | } 424 | 425 | if (V3_Save_FINE != map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr)) { 426 | 427 | V3 = SUBDIVISION[round(analogRead(DELAY_3)/32)]; 428 | save_timer_division_7 = millis(); 429 | Check_11 = true; 430 | D3_Save = map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr); 431 | V3_Save = map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr); 432 | R3_Save = map(analogRead(DELAY_3), 0, 1023, 0, Pot_thr); 433 | } 434 | 435 | if (V4_Save_FINE != map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr)) { 436 | 437 | V4 = SUBDIVISION[round(analogRead(DELAY_4)/32)]; 438 | save_timer_division_8 = millis(); 439 | Check_12 = true; 440 | D4_Save = map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr); 441 | V4_Save = map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr); 442 | R1_Save = map(analogRead(DELAY_4), 0, 1023, 0, Pot_thr); 443 | } 444 | 445 | 446 | 447 | 448 | } 449 | 450 | 451 | 452 | if ((millis() - save_timer_delay_1 > save_time_delay) && (Check_1 == true)) { //Save when Delay has changed and Save Time Has Expired 453 | EEPROM.write(4, D1); 454 | EEPROM.write(12, V1_Save); 455 | EEPROM.write(20, V1_Save_FINE); 456 | EEPROM.write(28, R1_Save); 457 | Check_1 = false; 458 | } 459 | 460 | if ((millis() - save_timer_delay_2 > save_time_delay) && (Check_2 == true)) { 461 | EEPROM.write(5, D2); 462 | EEPROM.write(13, V2_Save); 463 | EEPROM.write(21, V2_Save_FINE); 464 | EEPROM.write(29, R2_Save); 465 | Check_2 = false; 466 | } 467 | 468 | if ((millis() - save_timer_delay_3 > save_time_delay) && (Check_3 == true)) { 469 | EEPROM.write(6, D3); 470 | EEPROM.write(14, V3_Save); 471 | EEPROM.write(22, V3_Save_FINE); 472 | EEPROM.write(30, R3_Save); 473 | Check_3 = false; 474 | } 475 | 476 | if ((millis() - save_timer_delay_4 > save_time_delay) && (Check_4 == true)) { 477 | EEPROM.write(7, D4); 478 | EEPROM.write(15, V4_Save); 479 | EEPROM.write(23, V4_Save_FINE); 480 | EEPROM.write(31, R4_Save); 481 | Check_4 = false; 482 | } 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | if ((millis() - save_timer_reset_1 > save_time_reset) && (Check_13 == true)) { //Save when Reset has changed and Save Time Has Expired 491 | EEPROM.write(24, constrain(R1,0,255)); 492 | EEPROM.write(12, V1_Save); 493 | EEPROM.write(20, V1_Save_FINE); 494 | EEPROM.write(16, D1_Save); 495 | Check_13 = false; 496 | Serial.println(R1); 497 | } 498 | 499 | if ((millis() - save_timer_reset_2 > save_time_reset) && (Check_14 == true)) { 500 | EEPROM.write(25, constrain(R2,0,255)); 501 | EEPROM.write(13, V2_Save); 502 | EEPROM.write(21, V2_Save_FINE); 503 | EEPROM.write(17, D2_Save); 504 | Check_14 = false; 505 | } 506 | 507 | if ((millis() - save_timer_reset_3 > save_time_reset) && (Check_15 == true)) { 508 | EEPROM.write(26, constrain(R3,0,255)); 509 | EEPROM.write(14, V3_Save); 510 | EEPROM.write(22, V3_Save_FINE); 511 | EEPROM.write(18, D3_Save); 512 | Check_15 = false; 513 | } 514 | 515 | if ((millis() - save_timer_reset_4 > save_time_reset) && (Check_16 == true)) { 516 | EEPROM.write(27, constrain(R4,0,255)); 517 | EEPROM.write(15, V4_Save); 518 | EEPROM.write(23, V4_Save_FINE); 519 | EEPROM.write(19, D4_Save); 520 | Check_16 = false; 521 | } 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | if ((millis() - save_timer_division_1 > save_time_division) && (Check_5 == true)) { //Save when Division has changed and Save Time Has Expired 532 | EEPROM.write(8, constrain(V1,0,255)); 533 | EEPROM.write(16, D1_Save); 534 | EEPROM.write(20, V1_Save_FINE); 535 | EEPROM.write(28, R1_Save); 536 | Check_5 = false; 537 | } 538 | 539 | if ((millis() - save_timer_division_2 > save_time_division) && (Check_6 == true)) { 540 | EEPROM.write(9, constrain(V2,0,255)); 541 | EEPROM.write(17, D2_Save); 542 | EEPROM.write(21, V2_Save_FINE); 543 | EEPROM.write(29, R2_Save); 544 | Check_6 = false; 545 | } 546 | 547 | if ((millis() - save_timer_division_3 > save_time_division) && (Check_7 == true)) { 548 | EEPROM.write(10, constrain(V3,0,255)); 549 | EEPROM.write(18, D3_Save); 550 | EEPROM.write(22, V3_Save_FINE); 551 | EEPROM.write(30, R3_Save); 552 | Check_7 = false; 553 | } 554 | 555 | if ((millis() - save_timer_division_4 > save_time_division) && (Check_8 == true)) { 556 | EEPROM.write(11, constrain(V4,0,255)); 557 | EEPROM.write(19, D4_Save); 558 | EEPROM.write(23, V4_Save_FINE); 559 | EEPROM.write(31, R4_Save); 560 | Check_8 = false; 561 | } 562 | 563 | 564 | 565 | 566 | if ((millis() - save_timer_division_5 > save_time_division) && (Check_9 == true)) { //Save when Fine Division has changed and Save Time Has Expired 567 | EEPROM.write(8, constrain(V1,0,255)); 568 | EEPROM.write(16, D1_Save); 569 | EEPROM.write(12, V1_Save); 570 | EEPROM.write(28, R1_Save); 571 | Check_9 = false; 572 | } 573 | 574 | if ((millis() - save_timer_division_6 > save_time_division) && (Check_10 == true)) { 575 | EEPROM.write(9, constrain(V2,0,255)); 576 | EEPROM.write(17, D2_Save); 577 | EEPROM.write(13, V2_Save); 578 | EEPROM.write(29, R2_Save); 579 | Check_10 = false; 580 | } 581 | 582 | if ((millis() - save_timer_division_7 > save_time_division) && (Check_11 == true)) { 583 | EEPROM.write(10, constrain(V3,0,255)); 584 | EEPROM.write(18, D3_Save); 585 | EEPROM.write(14, V3_Save); 586 | EEPROM.write(30, R3_Save); 587 | Check_11 = false; 588 | } 589 | 590 | if ((millis() - save_timer_division_8 > save_time_division) && (Check_12 == true)) { 591 | EEPROM.write(11, constrain(V4,0,255)); 592 | EEPROM.write(19, D4_Save); 593 | EEPROM.write(15, V4_Save); 594 | EEPROM.write(31, R4_Save); 595 | Check_12 = false; 596 | } 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | if ((clock_timer_1 > 0) && (millis() - clock_timer_1 > Pulse_Length + D1)) { // Set Master Clock States low after Pulse_Lenghts Time 608 | MCS_1 = false; 609 | clock_timer_1 = 0; 610 | } 611 | 612 | if ((clock_timer_2 > 0) && (millis() - clock_timer_2 > Pulse_Length + D2)) { 613 | MCS_2 = false; 614 | clock_timer_2 = 0; 615 | } 616 | 617 | if ((clock_timer_3 > 0) && (millis() - clock_timer_3 > Pulse_Length + D3)) { 618 | MCS_3 = false; 619 | clock_timer_3 = 0; 620 | } 621 | 622 | if ((clock_timer_4 > 0) && (millis() - clock_timer_4 > Pulse_Length + D4)) { 623 | MCS_4 = false; 624 | clock_timer_4 = 0; 625 | } 626 | 627 | 628 | 629 | 630 | 631 | if ((reset_timer_1 > 0) && (millis() - reset_timer_1 > Pulse_Length + D1)) { // Set Master Reset States low after Pulse_Lenghts Time 632 | MCS_5 = false; 633 | reset_timer_1 = 0; 634 | } 635 | 636 | if ((reset_timer_2 > 0) && (millis() - reset_timer_2 > Pulse_Length + D2)) { 637 | MCS_6 = false; 638 | reset_timer_2 = 0; 639 | } 640 | 641 | if ((reset_timer_3 > 0) && (millis() - reset_timer_3 > Pulse_Length + D3)) { 642 | MCS_7 = false; 643 | reset_timer_3 = 0; 644 | } 645 | 646 | if ((reset_timer_4 > 0) && (millis() - reset_timer_4 > Pulse_Length + D4)) { 647 | MCS_8 = false; 648 | reset_timer_4 = 0; 649 | } 650 | 651 | 652 | 653 | 654 | 655 | 656 | if ((MCS_1 == true) && (millis() - clock_timer_1 >= D1)) { //Set Clockpins HIGH or LOW with Delays 657 | digitalWrite(CLOCK_1, HIGH); 658 | } 659 | else { 660 | digitalWrite(CLOCK_1, LOW); 661 | } 662 | 663 | 664 | 665 | if ((MCS_2 == true) && (millis() - clock_timer_2 >= D2)) { 666 | digitalWrite(CLOCK_2, HIGH); 667 | } 668 | else { 669 | digitalWrite(CLOCK_2, LOW); 670 | } 671 | 672 | 673 | 674 | if ((MCS_3 == true) && (millis() - clock_timer_3 >= D3)) { 675 | digitalWrite(CLOCK_3, HIGH); 676 | } 677 | else { 678 | digitalWrite(CLOCK_3, LOW); 679 | } 680 | 681 | 682 | 683 | if ((MCS_4 == true) && (millis() - clock_timer_4 >= D4)) { 684 | digitalWrite(CLOCK_4, HIGH); 685 | } 686 | else { 687 | digitalWrite(CLOCK_4, LOW); 688 | } 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | if ((MCS_5 == true) && (millis() - reset_timer_1 >= D1)) { //Set Reset Pins High or Low (Only used for LED but could be used to send reset triggers out through jacks!!!) 699 | digitalWrite(RESET_1, HIGH); 700 | } 701 | else { 702 | digitalWrite(RESET_1, LOW); 703 | } 704 | 705 | 706 | 707 | if ((MCS_6 == true) && (millis() - reset_timer_2 >= D2)) { 708 | digitalWrite(RESET_2, HIGH); 709 | } 710 | else { 711 | digitalWrite(RESET_2, LOW); 712 | } 713 | 714 | 715 | 716 | if ((MCS_7 == true) && (millis() - reset_timer_3 >= D3)) { 717 | digitalWrite(RESET_3, HIGH); 718 | } 719 | else { 720 | digitalWrite(RESET_3, LOW); 721 | } 722 | 723 | 724 | 725 | if ((MCS_8 == true) && (millis() - reset_timer_4 >= D4)) { 726 | digitalWrite(RESET_4, HIGH); 727 | } 728 | else { 729 | digitalWrite(RESET_4, LOW); 730 | } 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | //MIDI EVENT 746 | 747 | 748 | midiEventPacket_t rx = MidiUSB.read(); // listen for new MIDI messages 749 | switch (rx.byte1) { 750 | 751 | case 0xF8: //Clock 752 | 753 | 754 | 755 | if (millis() > clock_timeout_1 + 300) clock_count_1 = 0; // Prevents Clock from starting in between quarter notes after clock is restarted! 756 | clock_timeout_1 = millis(); 757 | 758 | if (millis() > clock_timeout_2 + 300) clock_count_2 = 0; 759 | clock_timeout_2 = millis(); 760 | 761 | if (millis() > clock_timeout_3 + 300) clock_count_3 = 0; 762 | clock_timeout_3 = millis(); 763 | 764 | if (millis() > clock_timeout_4 + 300) clock_count_4 = 0; 765 | clock_timeout_4 = millis(); 766 | 767 | 768 | if (millis() > reset_timeout_1 + 300) reset_count_1 = 0; // Prevents Reset from starting in between quarter notes after clock is restarted! 769 | reset_timeout_1 = millis(); 770 | 771 | if (millis() > reset_timeout_2 + 300) reset_count_2 = 0; 772 | reset_timeout_2 = millis(); 773 | 774 | if (millis() > reset_timeout_3 + 300) reset_count_3 = 0; 775 | reset_timeout_3 = millis(); 776 | 777 | if (millis() > reset_timeout_4 + 300) reset_count_4 = 0; 778 | reset_timeout_4 = millis(); 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | if (clock_count_1 == 0) { //Clock Counter gets pushed +1 and Master Clock State gets enabled 788 | MCS_1 = true; 789 | clock_timer_1 = millis(); 790 | } 791 | clock_count_1++; 792 | 793 | if (clock_count_2 == 0) { 794 | MCS_2 = true; 795 | clock_timer_2 = millis(); 796 | } 797 | clock_count_2++; 798 | 799 | if (clock_count_3 == 0) { 800 | MCS_3 = true; 801 | clock_timer_3 = millis(); 802 | } 803 | clock_count_3++; 804 | 805 | if (clock_count_4 == 0) { 806 | MCS_4 = true; 807 | clock_timer_4 = millis(); 808 | } 809 | clock_count_4++; 810 | 811 | 812 | 813 | if (reset_count_1 == 0) { //Clock Counter gets pushed +1 and Master Reset State gets enabled 814 | MCS_5 = true; 815 | reset_timer_1 = millis(); 816 | } 817 | reset_count_1++; 818 | 819 | if (reset_count_2 == 0) { 820 | MCS_6 = true; 821 | reset_timer_2 = millis(); 822 | } 823 | reset_count_2++; 824 | 825 | if (reset_count_3 == 0) { 826 | MCS_7 = true; 827 | reset_timer_3 = millis(); 828 | } 829 | reset_count_3++; 830 | 831 | if (reset_count_4 == 0) { 832 | MCS_8 = true; 833 | reset_timer_4 = millis(); 834 | } 835 | reset_count_4++; 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | if ((clock_count_1 >= V1) && (V1 <= 254)) { // Reset Clock Counter through Divisions: MIDI timing clock sends 24 pulses per quarter note. Send pulse only once every 12 pulses 846 | clock_count_1 = 0; 847 | } 848 | 849 | if ((clock_count_2 >= V2) && (V2 <= 254)) { 850 | clock_count_2 = 0; 851 | } 852 | 853 | if ((clock_count_3 >= V3) && (V3 <= 254)) { 854 | clock_count_3 = 0; 855 | } 856 | 857 | if ((clock_count_4 >= V4) && (V4 <= 254)) { 858 | clock_count_4 = 0; 859 | } 860 | 861 | 862 | 863 | 864 | if ((reset_count_1 >= R1) && (R1 <= 254)) { // Reset Clock Counter through Divisions 865 | reset_count_1 = 0; 866 | clock_count_1 = 0; 867 | } 868 | 869 | if ((reset_count_2 >= R2) && (R2 <= 254)) { 870 | reset_count_2 = 0; 871 | clock_count_2 = 0; 872 | } 873 | 874 | if ((reset_count_3 >= R3) && (R3 <= 254)) { 875 | reset_count_3 = 0; 876 | clock_count_3 = 0; 877 | } 878 | 879 | if ((reset_count_4 >= R4) && (R4 <= 254)) { 880 | reset_count_4 = 0; 881 | clock_count_4 = 0; 882 | } 883 | 884 | 885 | 886 | break; 887 | } 888 | 889 | 890 | } 891 | -------------------------------------------------------------------------------- /ArduinoMidiClocker_FINAL/ArduinoMidiClocker_1.1.1.ino: -------------------------------------------------------------------------------- 1 | #include "MIDIUSB.h" 2 | #include 3 | #include 4 | 5 | 6 | 7 | 8 | //HARDWAR PIN NUMBERS: 9 | 10 | #define CLOCK_1 1 //CLOCK LEDS AND OUTPUTS 11 | #define CLOCK_2 0 12 | #define CLOCK_3 2 13 | #define CLOCK_4 3 14 | 15 | #define RESET_1 4 //RESET LEDS 16 | #define RESET_2 5 17 | #define RESET_3 6 18 | #define RESET_4 7 19 | 20 | #define DELAY_1 A3 //POTIS 21 | #define DELAY_2 A2 22 | #define DELAY_3 A1 23 | #define DELAY_4 A0 24 | 25 | 26 | 27 | #define DELAY 8 // Button Pins 28 | #define SUBDIV 9 29 | #define RESET 10 30 | 31 | #define DOUBLE_CLICK_TIME 500 // Max Time for Double Clicking in ms 32 | 33 | 34 | 35 | #define DEL_RNG 50 // Define Delay Range in ms 36 | 37 | #define SWG_RNG 50 // Define Swing Range in ms 38 | 39 | #define DIV_RNG 7 // Define Clock Division Range: 0 = 2Pulse/1Sixteenth1 = 1 Pulse/Sixteenth, 2 = 1Pulse/Eights, 3 = 1 Pulse/1Quater, 4 = 1Pulse/2Quater, 5 = 1Pulse/1Bar, 6 = 1Pulse/2Bars, 7 = None 40 | 41 | #define RES_RNG 7 // Define Reset Division Rannge: 0 = 2Pulse/1Sixteenth1 = 1 Pulse/Sixteenth, 2 = 1Pulse/Eights, 3 = 1 Pulse/1Quater, 4 = 1Pulse/2Quater, 5 = 1Pulse/1Bar, 6 = 1Pulse/2Bars, 7 = None 42 | 43 | int SUBDIVISION[] = {255,255,255,255,240,216,192,168,144,120,96,72,60,54,48,42,30,27,24,21,18,15,12,9,8,7,6,5,4,3,3,3}; // Mapping Array for Fine Division 44 | 45 | #define save_time_delay 30000 // Save Times to Spare on EEPROM Cycles in ms 46 | #define save_time_division 30000 47 | #define save_time_reset 30000 48 | #define save_time_random 30000 49 | #define save_time_swing 30000 50 | 51 | #define Pot_thr 5 // Deadband of Pot for Movement detection +/- this value from 1023 52 | #define Buff 4 53 | 54 | #define Pulse_Length 15 // Output Pulse Duration in ms (and for Pink LEDS) 55 | #define Pulse_Length_Reset 10 //Pulse lenght for Reset Pulse and Green LED (Can adjust Green LED Brightness here 56 | 57 | 58 | 59 | 60 | int D1 = EEPROM.read(4); //Read Stored Values only once when powered up 61 | int D2 = EEPROM.read(5); 62 | int D3 = EEPROM.read(6); 63 | int D4 = EEPROM.read(7); 64 | 65 | 66 | int S1 = EEPROM.read(0); 67 | int S2 = EEPROM.read(1); 68 | int S3 = EEPROM.read(2); 69 | int S4 = EEPROM.read(3); 70 | 71 | 72 | int V1 = EEPROM.read(8); 73 | int V2 = EEPROM.read(9); 74 | int V3 = EEPROM.read(10); 75 | int V4 = EEPROM.read(11); 76 | 77 | 78 | int R1 = EEPROM.read(24); 79 | int R2 = EEPROM.read(25); 80 | int R3 = EEPROM.read(26); 81 | int R4 = EEPROM.read(27); 82 | 83 | 84 | int RND1 = EEPROM.read(12); 85 | int RND2 = EEPROM.read(13); 86 | int RND3 = EEPROM.read(14); 87 | int RND4 = EEPROM.read(15); 88 | 89 | 90 | int Pot1_Save = (EEPROM.read(16) << 8) + EEPROM.read(17); //Pot Position Saves 91 | int Pot2_Save = (EEPROM.read(18) << 8) + EEPROM.read(19); 92 | int Pot3_Save = (EEPROM.read(20) << 8) + EEPROM.read(21); 93 | int Pot4_Save = (EEPROM.read(22) << 8) + EEPROM.read(23); 94 | 95 | 96 | 97 | 98 | 99 | 100 | // SETUP 101 | 102 | 103 | 104 | 105 | void setup() 106 | { 107 | pinMode(CLOCK_1, OUTPUT); // Pin Configuration 108 | pinMode(CLOCK_2, OUTPUT); 109 | pinMode(CLOCK_3, OUTPUT); 110 | pinMode(CLOCK_4, OUTPUT); 111 | 112 | pinMode(RESET_1, OUTPUT); 113 | pinMode(RESET_2, OUTPUT); 114 | pinMode(RESET_3, OUTPUT); 115 | pinMode(RESET_4, OUTPUT); 116 | 117 | 118 | pinMode(DELAY_1, INPUT); 119 | pinMode(DELAY_2, INPUT); 120 | pinMode(DELAY_3, INPUT); 121 | pinMode(DELAY_4, INPUT); 122 | 123 | pinMode(DELAY, INPUT_PULLUP); // Pullup Modes for Button Pins 124 | pinMode(SUBDIV, INPUT_PULLUP); 125 | pinMode(RESET, INPUT_PULLUP); 126 | 127 | 128 | digitalWrite(CLOCK_1, LOW); // Put Outputs Low 129 | digitalWrite(CLOCK_2, LOW); 130 | digitalWrite(CLOCK_3, LOW); 131 | digitalWrite(CLOCK_4, LOW); 132 | 133 | digitalWrite(RESET_1, LOW); 134 | digitalWrite(RESET_2, LOW); 135 | digitalWrite(RESET_3, LOW); 136 | digitalWrite(RESET_4, LOW); 137 | 138 | 139 | SPI.begin(); 140 | 141 | Serial.begin(115200); 142 | 143 | 144 | } 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | //LOOP 158 | 159 | 160 | 161 | 162 | void loop() 163 | { 164 | static unsigned long clock_timer_1 = 0, clock_timeout_1 = 0; // Clock Timers 165 | static unsigned long clock_timer_2 = 0, clock_timeout_2 = 0; 166 | static unsigned long clock_timer_3 = 0, clock_timeout_3 = 0; 167 | static unsigned long clock_timer_4 = 0, clock_timeout_4 = 0; 168 | 169 | static unsigned long reset_timer_1 = 0, reset_timeout_1 = 0; // Reset Timers 170 | static unsigned long reset_timer_2 = 0, reset_timeout_2 = 0; 171 | static unsigned long reset_timer_3 = 0, reset_timeout_3 = 0; 172 | static unsigned long reset_timer_4 = 0, reset_timeout_4 = 0; 173 | 174 | static unsigned long master_timer = 0, master_timeout = 0; 175 | 176 | 177 | static unsigned long save_timer_delay_1 = 0; // Timer for delaying Saving Time 178 | static unsigned long save_timer_delay_2 = 0; 179 | static unsigned long save_timer_delay_3 = 0; 180 | static unsigned long save_timer_delay_4 = 0; 181 | 182 | static unsigned long save_timer_division_1 = 0; 183 | static unsigned long save_timer_division_2 = 0; 184 | static unsigned long save_timer_division_3 = 0; 185 | static unsigned long save_timer_division_4 = 0; 186 | 187 | 188 | static unsigned long save_timer_division_5 = 0; 189 | static unsigned long save_timer_division_6 = 0; 190 | static unsigned long save_timer_division_7 = 0; 191 | static unsigned long save_timer_division_8 = 0; 192 | 193 | static unsigned long save_timer_reset_1 = 0; 194 | static unsigned long save_timer_reset_2 = 0; 195 | static unsigned long save_timer_reset_3 = 0; 196 | static unsigned long save_timer_reset_4 = 0; 197 | 198 | static unsigned long save_timer_random_1 = 0; 199 | static unsigned long save_timer_random_2 = 0; 200 | static unsigned long save_timer_random_3 = 0; 201 | static unsigned long save_timer_random_4 = 0; 202 | 203 | static unsigned long save_timer_swing_1 = 0; 204 | static unsigned long save_timer_swing_2 = 0; 205 | static unsigned long save_timer_swing_3 = 0; 206 | static unsigned long save_timer_swing_4 = 0; 207 | 208 | 209 | 210 | 211 | static unsigned int clock_count_1 = 0; //Clock Counters 212 | static unsigned int clock_count_2 = 0; 213 | static unsigned int clock_count_3 = 0; 214 | static unsigned int clock_count_4 = 0; 215 | 216 | static unsigned int reset_count_1 = 0; //Reset Counters 217 | static unsigned int reset_count_2 = 0; 218 | static unsigned int reset_count_3 = 0; 219 | static unsigned int reset_count_4 = 0; 220 | 221 | static unsigned int master_count = 0; 222 | 223 | static bool MCS_1 = false; // Master Clock States (undelayed Clock State) 224 | static bool MCS_2 = false; 225 | static bool MCS_3 = false; 226 | static bool MCS_4 = false; 227 | 228 | static bool MCS_5 = false; // Master Reset States (undelayed Reset State) 229 | static bool MCS_6 = false; 230 | static bool MCS_7 = false; 231 | static bool MCS_8 = false; 232 | 233 | static bool MCS = false; 234 | 235 | 236 | static bool Check_1 = false; // Check bools for Save time delays 4 for each Parameter 237 | static bool Check_2 = false; 238 | static bool Check_3 = false; 239 | static bool Check_4 = false; 240 | static bool Check_5 = false; 241 | static bool Check_6 = false; 242 | static bool Check_7 = false; 243 | static bool Check_8 = false; 244 | static bool Check_9 = false; 245 | static bool Check_10 = false; 246 | static bool Check_11 = false; 247 | static bool Check_12 = false; 248 | static bool Check_13 = false; 249 | static bool Check_14 = false; 250 | static bool Check_15 = false; 251 | static bool Check_16 = false; 252 | static bool Check_17 = false; 253 | static bool Check_18 = false; 254 | static bool Check_19 = false; 255 | static bool Check_20 = false; 256 | static bool Check_21 = false; 257 | static bool Check_22 = false; 258 | static bool Check_23 = false; 259 | static bool Check_24 = false; 260 | 261 | 262 | static bool Reset_Check = false; 263 | 264 | 265 | static unsigned int rnd1 = 100; 266 | static unsigned int rnd2 = 100; 267 | static unsigned int rnd3 = 100; 268 | static unsigned int rnd4 = 100; 269 | 270 | static bool rndcheck1 = false; 271 | static bool rndcheck2 = false; 272 | static bool rndcheck3 = false; 273 | static bool rndcheck4 = false; 274 | 275 | 276 | 277 | static bool swing_state = false; 278 | 279 | 280 | static unsigned int s1 = 0; 281 | static unsigned int s2 = 0; 282 | static unsigned int s3 = 0; 283 | static unsigned int s4 = 0; 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | bool Delay_Mode = false; // Modes Detection (Shift keys) 296 | bool Division_Mode = false; 297 | bool Subdivision_Mode = false; 298 | bool Reset_Division_Mode = false; 299 | bool Random_Mode = false; 300 | bool Reset_Parameter_Mode = false; 301 | bool Swing_Mode = false; 302 | 303 | 304 | 305 | 306 | static unsigned long Switch_Timer_d = 0; //Timers and Latches for Click counters (Double Clicks) 307 | static unsigned long Switch_Timer_s = 0; 308 | static unsigned long Switch_Timer_r = 0; 309 | 310 | static unsigned int Switch_Counter_d = 0; 311 | static unsigned int Switch_Counter_s = 0; 312 | static unsigned int Switch_Counter_r = 0; 313 | 314 | static bool latch_d = false; 315 | static bool latch_s = false; 316 | static bool latch_r = false; 317 | 318 | 319 | 320 | bool d = !digitalRead(DELAY); //Switches Read In 321 | bool s = !digitalRead(SUBDIV); 322 | bool r = !digitalRead(RESET); 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | if (master_count > 5) { 331 | 332 | s1 = S1; 333 | s2 = S2; 334 | s3 = S3; 335 | s4 = S4; 336 | 337 | } 338 | 339 | 340 | 341 | else if (master_count < 6) { //Set Swin delay for each channel if its an odd number of 16th steps 342 | 343 | s1 = 0; 344 | s2 = 0; 345 | s3 = 0; 346 | s4 = 0; 347 | 348 | } 349 | 350 | 351 | 352 | 353 | 354 | if ((d == true) && (latch_d == false)) { //Count Times Button Pressed 355 | Switch_Counter_d++; 356 | Switch_Timer_d = millis(); 357 | latch_d = true; 358 | } 359 | else if (d == false) { 360 | latch_d = false; 361 | } 362 | 363 | 364 | 365 | if ((s == true) && (latch_s == false)) { 366 | Switch_Counter_s++; 367 | Switch_Timer_s = millis(); 368 | latch_s = true; 369 | } 370 | else if (s == false) { 371 | latch_s = false; 372 | } 373 | 374 | 375 | 376 | if ((r == true) && (latch_r == false)) { 377 | Switch_Counter_r++; 378 | Switch_Timer_r = millis(); 379 | latch_r = true; 380 | } 381 | else if (r == false) { 382 | latch_r = false; 383 | } 384 | 385 | 386 | 387 | 388 | 389 | if ((millis() >= Switch_Timer_d + DOUBLE_CLICK_TIME) && (d == false)) { //Reset Count when no Button Pressed 390 | Switch_Counter_d = 0; 391 | } 392 | 393 | if ((millis() >= Switch_Timer_s + DOUBLE_CLICK_TIME) && (s == false)) { 394 | Switch_Counter_s = 0; 395 | } 396 | 397 | if ((millis() >= Switch_Timer_r + DOUBLE_CLICK_TIME) && (r == false)) { 398 | Switch_Counter_r = 0; 399 | } 400 | 401 | 402 | 403 | 404 | 405 | if ((d == true) && (Switch_Counter_d == 2)) { // Mode Activation and Deactivation 406 | Delay_Mode = true; 407 | } 408 | else { 409 | Delay_Mode = false; 410 | } 411 | 412 | 413 | if ((r == true) && (Switch_Counter_r == 1)) { 414 | Reset_Division_Mode = true; 415 | } 416 | else { 417 | Reset_Division_Mode = false; 418 | } 419 | 420 | 421 | if ((s == true) && (Switch_Counter_s == 1)) { 422 | Subdivision_Mode = true; 423 | } 424 | else { 425 | Subdivision_Mode = false; 426 | } 427 | 428 | 429 | if ((r == true) && (Switch_Counter_r == 2)) { 430 | Reset_Parameter_Mode = true; 431 | } 432 | else { 433 | Reset_Parameter_Mode = false; 434 | } 435 | 436 | 437 | if ((s == true) && (Switch_Counter_s == 2)) { 438 | Random_Mode = true; 439 | } 440 | else { 441 | Random_Mode = false; 442 | } 443 | 444 | 445 | if ((d == true) && (Switch_Counter_d == 1)) { 446 | Swing_Mode = true; 447 | } 448 | else { 449 | Swing_Mode = false; 450 | } 451 | 452 | 453 | 454 | if ((d == false) && (r == false) && (s == false)) { 455 | Division_Mode = true; 456 | } 457 | else { 458 | Division_Mode = false; 459 | } 460 | 461 | 462 | 463 | 464 | 465 | if (Delay_Mode == true) { 466 | 467 | 468 | if ((analogRead(DELAY_1) <= Pot1_Save - Pot_thr) || (analogRead(DELAY_1) >= Pot1_Save + Pot_thr)) { 469 | 470 | D1 = int(map(analogRead(DELAY_1), 0+Buff, 1023-Buff, 0, DEL_RNG)); // Delay Wert Auslesen der Potentiometer 471 | save_timer_delay_1 = millis(); 472 | Check_1 = true; 473 | Pot1_Save = analogRead(DELAY_1); 474 | 475 | } 476 | 477 | 478 | if ((analogRead(DELAY_2) <= Pot2_Save - Pot_thr) || (analogRead(DELAY_2) >= Pot2_Save + Pot_thr)) { 479 | 480 | D2 = int(map(analogRead(DELAY_2), 0+Buff, 1023-Buff, 0, DEL_RNG)); 481 | save_timer_delay_2 = millis(); 482 | Check_2 = true; 483 | Pot2_Save = analogRead(DELAY_2); 484 | 485 | } 486 | 487 | 488 | if ((analogRead(DELAY_3) <= Pot3_Save - Pot_thr) || (analogRead(DELAY_3) >= Pot3_Save + Pot_thr)) { 489 | 490 | D3 = int(map(analogRead(DELAY_3), 0+Buff, 1023-Buff, 0, DEL_RNG)); 491 | save_timer_delay_3 = millis(); 492 | Check_3 = true; 493 | Pot3_Save = analogRead(DELAY_3); 494 | 495 | } 496 | 497 | 498 | if ((analogRead(DELAY_4) <= Pot4_Save - Pot_thr) || (analogRead(DELAY_4) >= Pot4_Save + Pot_thr)) { 499 | 500 | D4 = int(map(analogRead(DELAY_4), 0+Buff, 1023-Buff, 0, DEL_RNG)); 501 | save_timer_delay_4 = millis(); 502 | Check_4 = true; 503 | Pot4_Save = analogRead(DELAY_4); 504 | 505 | } 506 | } 507 | 508 | 509 | 510 | 511 | 512 | if (Swing_Mode == true) { 513 | 514 | 515 | if ((analogRead(DELAY_1) <= Pot1_Save - Pot_thr) || (analogRead(DELAY_1) >= Pot1_Save + Pot_thr)) { 516 | 517 | S1 = int(map(analogRead(DELAY_1), 0+Buff, 1023-Buff, 0, SWG_RNG)); // Delay Wert Auslesen der Potentiometer 518 | save_timer_swing_1 = millis(); 519 | Check_21 = true; 520 | Pot1_Save = analogRead(DELAY_1); 521 | 522 | } 523 | 524 | 525 | if ((analogRead(DELAY_2) <= Pot2_Save - Pot_thr) || (analogRead(DELAY_2) >= Pot2_Save + Pot_thr)) { 526 | 527 | S2 = int(map(analogRead(DELAY_2), 0+Buff, 1023-Buff, 0, SWG_RNG)); 528 | save_timer_swing_2 = millis(); 529 | Check_22 = true; 530 | Pot2_Save = analogRead(DELAY_2); 531 | 532 | } 533 | 534 | 535 | if ((analogRead(DELAY_3) <= Pot3_Save - Pot_thr) || (analogRead(DELAY_3) >= Pot3_Save + Pot_thr)) { 536 | 537 | S3 = int(map(analogRead(DELAY_3), 0+Buff, 1023-Buff, 0, SWG_RNG)); 538 | save_timer_swing_3 = millis(); 539 | Check_23 = true; 540 | Pot3_Save = analogRead(DELAY_3); 541 | 542 | } 543 | 544 | 545 | if ((analogRead(DELAY_4) <= Pot4_Save - Pot_thr) || (analogRead(DELAY_4) >= Pot4_Save + Pot_thr)) { 546 | 547 | S4 = int(map(analogRead(DELAY_4), 0+Buff, 1023-Buff, 0, SWG_RNG)); 548 | save_timer_swing_4 = millis(); 549 | Check_24 = true; 550 | Pot4_Save = analogRead(DELAY_4); 551 | 552 | } 553 | } 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | else if (Reset_Division_Mode == true) { 562 | 563 | if ((analogRead(DELAY_1) <= Pot1_Save - Pot_thr) || (analogRead(DELAY_1) >= Pot1_Save + Pot_thr)) { 564 | 565 | R1 = 3 * round(pow(2, int(map(analogRead(DELAY_1), 0+Buff, 1023-Buff, RES_RNG, 0)))); // Reset Wert Auslesen der Potentiometer 566 | save_timer_reset_1 = millis(); 567 | Check_13 = true; 568 | Pot1_Save = analogRead(DELAY_1); 569 | 570 | } 571 | 572 | if ((analogRead(DELAY_2) <= Pot2_Save - Pot_thr) || (analogRead(DELAY_2) >= Pot2_Save + Pot_thr)) { 573 | 574 | R2 = 3 * round(pow(2, int(map(analogRead(DELAY_2), 0+Buff, 1023-Buff, RES_RNG, 0)))); 575 | save_timer_reset_2 = millis(); 576 | Check_14 = true; 577 | Pot2_Save = analogRead(DELAY_2); 578 | 579 | } 580 | 581 | if ((analogRead(DELAY_3) <= Pot3_Save - Pot_thr) || (analogRead(DELAY_3) >= Pot3_Save + Pot_thr)) { 582 | 583 | R3 = 3 * round(pow(2, int(map(analogRead(DELAY_3), 0+Buff, 1023-Buff, RES_RNG, 0)))); 584 | save_timer_reset_3 = millis(); 585 | Check_15 = true; 586 | Pot3_Save = analogRead(DELAY_3); 587 | 588 | } 589 | 590 | if ((analogRead(DELAY_4) <= Pot4_Save - Pot_thr) || (analogRead(DELAY_4) >= Pot4_Save + Pot_thr)) { 591 | 592 | R4 = 3 * round(pow(2, int(map(analogRead(DELAY_4), 0+Buff, 1023-Buff, RES_RNG, 0)))); 593 | save_timer_reset_4 = millis(); 594 | Check_16 = true; 595 | Pot4_Save = analogRead(DELAY_4); 596 | 597 | } 598 | 599 | } 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | else if (Division_Mode == true) { 609 | 610 | if ((analogRead(DELAY_1) <= Pot1_Save - Pot_thr) || (analogRead(DELAY_1) >= Pot1_Save + Pot_thr)) { 611 | 612 | V1 = 3 * round(pow(2, int(map(analogRead(DELAY_1), 0+Buff, 1023-Buff, DIV_RNG, 0)))); // Division Wert Auslesen der Potentiometer 613 | save_timer_division_1 = millis(); 614 | Check_5 = true; 615 | Pot1_Save = analogRead(DELAY_1); 616 | 617 | } 618 | 619 | if ((analogRead(DELAY_2) <= Pot2_Save - Pot_thr) || (analogRead(DELAY_2) >= Pot2_Save + Pot_thr)) { 620 | 621 | V2 = 3 * round(pow(2, int(map(analogRead(DELAY_2), 0+Buff, 1023-Buff, DIV_RNG, 0)))); 622 | save_timer_division_2 = millis(); 623 | Check_6 = true; 624 | Pot2_Save = analogRead(DELAY_2); 625 | 626 | } 627 | 628 | if ((analogRead(DELAY_3) <= Pot3_Save - Pot_thr) || (analogRead(DELAY_3) >= Pot3_Save + Pot_thr)) { 629 | 630 | V3 = 3 * round(pow(2, int(map(analogRead(DELAY_3), 0+Buff, 1023-Buff, DIV_RNG, 0)))); 631 | save_timer_division_3 = millis(); 632 | Check_7 = true; 633 | Pot3_Save = analogRead(DELAY_3); 634 | 635 | } 636 | 637 | if ((analogRead(DELAY_4) <= Pot4_Save - Pot_thr) || (analogRead(DELAY_4) >= Pot4_Save + Pot_thr)) { 638 | 639 | V4 = 3 * round(pow(2, int(map(analogRead(DELAY_4), 0+Buff, 1023-Buff, DIV_RNG, 0)))); 640 | save_timer_division_4 = millis(); 641 | Check_8 = true; 642 | Pot4_Save = analogRead(DELAY_4); 643 | 644 | } 645 | 646 | 647 | 648 | 649 | } 650 | 651 | 652 | 653 | 654 | 655 | else if (Subdivision_Mode == true) { 656 | 657 | if ((analogRead(DELAY_1) <= Pot1_Save - Pot_thr) || (analogRead(DELAY_1) >= Pot1_Save + Pot_thr)) { 658 | 659 | V1 = SUBDIVISION[round(map(analogRead(DELAY_1), 0+Buff, 1023-Buff, 0, 31))]; // Fine Division Wert Auslesen der Potentiometer 660 | save_timer_division_5 = millis(); 661 | Check_9 = true; 662 | Pot1_Save = analogRead(DELAY_1); 663 | 664 | 665 | } 666 | 667 | if ((analogRead(DELAY_2) <= Pot2_Save - Pot_thr) || (analogRead(DELAY_2) >= Pot2_Save + Pot_thr)) { 668 | 669 | V2 = SUBDIVISION[round(map(analogRead(DELAY_2), 0+Buff, 1023-Buff, 0, 311))]; 670 | save_timer_division_6 = millis(); 671 | Check_10 = true; 672 | Pot2_Save = analogRead(DELAY_2); 673 | 674 | } 675 | 676 | if ((analogRead(DELAY_3) <= Pot3_Save - Pot_thr) || (analogRead(DELAY_3) >= Pot3_Save + Pot_thr)) { 677 | 678 | V3 = SUBDIVISION[round(map(analogRead(DELAY_3), 0+Buff, 1023-Buff, 0, 31))]; 679 | save_timer_division_7 = millis(); 680 | Check_11 = true; 681 | Pot3_Save = analogRead(DELAY_3); 682 | 683 | } 684 | 685 | if ((analogRead(DELAY_4) <= Pot4_Save - Pot_thr) || (analogRead(DELAY_4) >= Pot4_Save + Pot_thr)) { 686 | 687 | V4 = SUBDIVISION[round(map(analogRead(DELAY_4), 0+Buff, 1023-Buff, 0, 31))]; 688 | save_timer_division_8 = millis(); 689 | Check_12 = true; 690 | Pot4_Save = analogRead(DELAY_4); 691 | 692 | } 693 | 694 | } 695 | 696 | 697 | 698 | else if (Random_Mode == true) { 699 | 700 | if ((analogRead(DELAY_1) <= Pot1_Save - Pot_thr) || (analogRead(DELAY_1) >= Pot1_Save + Pot_thr)) { 701 | 702 | RND1 = map(analogRead(DELAY_1),0+Buff, 1023-Buff,1,100); // Fine Division Wert Auslesen der Potentiometer 703 | save_timer_random_1 = millis(); 704 | Check_17 = true; 705 | Pot1_Save = analogRead(DELAY_1); 706 | 707 | 708 | } 709 | 710 | if ((analogRead(DELAY_2) <= Pot2_Save - Pot_thr) || (analogRead(DELAY_2) >= Pot2_Save + Pot_thr)) { 711 | 712 | RND2 = map(analogRead(DELAY_2),0+Buff, 1023-Buff,1,100); 713 | save_timer_random_2 = millis(); 714 | Check_18 = true; 715 | Pot2_Save = analogRead(DELAY_2); 716 | 717 | } 718 | 719 | if ((analogRead(DELAY_3) <= Pot3_Save - Pot_thr) || (analogRead(DELAY_3) >= Pot3_Save + Pot_thr)) { 720 | 721 | RND3 = map(analogRead(DELAY_3),0+Buff, 1023-Buff,1,100); 722 | save_timer_random_3 = millis(); 723 | Check_19 = true; 724 | Pot3_Save = analogRead(DELAY_3); 725 | 726 | } 727 | 728 | if ((analogRead(DELAY_4) <= Pot4_Save - Pot_thr) || (analogRead(DELAY_4) >= Pot4_Save + Pot_thr)) { 729 | 730 | RND4 = map(analogRead(DELAY_4),0+Buff, 1023-Buff,1,100); 731 | save_timer_random_4 = millis(); 732 | Check_20 = true; 733 | Pot4_Save = analogRead(DELAY_4); 734 | 735 | } 736 | 737 | } 738 | 739 | 740 | 741 | 742 | else if ((Reset_Parameter_Mode == true) && (Reset_Check == false)) { //Reset All Parameters Mode (except Delays) 743 | Reset_Check = true; 744 | 745 | V1 = 24; // Default Parameters to Reset to when Reset_Parameter_Mode was enabled 746 | V2 = 24; 747 | V3 = 24; 748 | V4 = 24; 749 | 750 | R1 = 96; 751 | R2 = 96; 752 | R3 = 96; 753 | R4 = 96; 754 | 755 | S1 = 0; 756 | S2 = 0; 757 | S3 = 0; 758 | S4 = 0; 759 | 760 | RND1 = 100; 761 | RND2 = 100; 762 | RND3 = 100; 763 | RND4 = 100; 764 | 765 | Pot1_Save = analogRead(DELAY_1); 766 | Pot2_Save = analogRead(DELAY_2); 767 | Pot3_Save = analogRead(DELAY_3); 768 | Pot4_Save = analogRead(DELAY_4); 769 | 770 | clock_count_1 = 0; 771 | clock_count_2 = 0; 772 | clock_count_3 = 0; 773 | clock_count_4 = 0; 774 | 775 | reset_count_1 = 0; 776 | reset_count_2 = 0; 777 | reset_count_3 = 0; 778 | reset_count_4 = 0; 779 | 780 | 781 | save_timer_delay_1 = millis(); 782 | save_timer_delay_2 = millis(); 783 | save_timer_delay_3 = millis(); 784 | save_timer_delay_4 = millis(); 785 | 786 | save_timer_division_1 = millis(); 787 | save_timer_division_2 = millis(); 788 | save_timer_division_3 = millis(); 789 | save_timer_division_4 = millis(); 790 | 791 | save_timer_reset_1 = millis(); 792 | save_timer_reset_2 = millis(); 793 | save_timer_reset_3 = millis(); 794 | save_timer_reset_4 = millis(); 795 | 796 | save_timer_random_1 = millis(); 797 | save_timer_random_2 = millis(); 798 | save_timer_random_3 = millis(); 799 | save_timer_random_4 = millis(); 800 | 801 | save_timer_swing_1 = millis(); 802 | save_timer_swing_2 = millis(); 803 | save_timer_swing_3 = millis(); 804 | save_timer_swing_4 = millis(); 805 | 806 | 807 | Check_1 = true; 808 | Check_2 = true; 809 | Check_3 = true; 810 | Check_4 = true; 811 | Check_5 = true; 812 | Check_6 = true; 813 | Check_7 = true; 814 | Check_8 = true; 815 | Check_13 = true; 816 | Check_14 = true; 817 | Check_15 = true; 818 | Check_16 = true; 819 | Check_17 = true; 820 | Check_18 = true; 821 | Check_19 = true; 822 | Check_20 = true; 823 | Check_21 = true; 824 | Check_22 = true; 825 | Check_23 = true; 826 | Check_24 = true; 827 | 828 | 829 | 830 | 831 | } 832 | 833 | 834 | 835 | if (Reset_Parameter_Mode == false) { 836 | Reset_Check = false; 837 | } 838 | 839 | 840 | 841 | 842 | 843 | if ((millis() - save_timer_delay_1 > save_time_delay) && (Check_1 == true)) { //Save when Delay has changed and Save Time Has Expired 844 | EEPROM.write(4, D1); 845 | writetoEEPROM(16, Pot1_Save); 846 | 847 | Check_1 = false; 848 | } 849 | 850 | if ((millis() - save_timer_delay_2 > save_time_delay) && (Check_2 == true)) { 851 | EEPROM.write(5, D2); 852 | writetoEEPROM(18, Pot2_Save); 853 | 854 | Check_2 = false; 855 | } 856 | 857 | if ((millis() - save_timer_delay_3 > save_time_delay) && (Check_3 == true)) { 858 | EEPROM.write(6, D3); 859 | writetoEEPROM(20, Pot3_Save); 860 | 861 | Check_3 = false; 862 | } 863 | 864 | if ((millis() - save_timer_delay_4 > save_time_delay) && (Check_4 == true)) { 865 | EEPROM.write(7, D4); 866 | writetoEEPROM(22, Pot4_Save); 867 | 868 | Check_4 = false; 869 | } 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | if ((millis() - save_timer_reset_1 > save_time_reset) && (Check_13 == true)) { //Save when Reset has changed and Save Time Has Expired 878 | EEPROM.write(24, constrain(R1,0,255)); 879 | writetoEEPROM(16, Pot1_Save); 880 | 881 | Check_13 = false; 882 | } 883 | 884 | if ((millis() - save_timer_reset_2 > save_time_reset) && (Check_14 == true)) { 885 | EEPROM.write(25, constrain(R2,0,255)); 886 | writetoEEPROM(18, Pot2_Save); 887 | 888 | Check_14 = false; 889 | } 890 | 891 | if ((millis() - save_timer_reset_3 > save_time_reset) && (Check_15 == true)) { 892 | EEPROM.write(26, constrain(R3,0,255)); 893 | writetoEEPROM(20, Pot3_Save); 894 | 895 | Check_15 = false; 896 | } 897 | 898 | if ((millis() - save_timer_reset_4 > save_time_reset) && (Check_16 == true)) { 899 | EEPROM.write(27, constrain(R4,0,255)); 900 | writetoEEPROM(22, Pot4_Save); 901 | 902 | Check_16 = false; 903 | } 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | if ((millis() - save_timer_division_1 > save_time_division) && (Check_5 == true)) { //Save when Division has changed and Save Time Has Expired 914 | EEPROM.write(8, constrain(V1,0,255)); 915 | writetoEEPROM(16, Pot1_Save); 916 | 917 | Check_5 = false; 918 | } 919 | 920 | if ((millis() - save_timer_division_2 > save_time_division) && (Check_6 == true)) { 921 | EEPROM.write(9, constrain(V2,0,255)); 922 | writetoEEPROM(18, Pot2_Save); 923 | 924 | Check_6 = false; 925 | } 926 | 927 | if ((millis() - save_timer_division_3 > save_time_division) && (Check_7 == true)) { 928 | EEPROM.write(10, constrain(V3,0,255)); 929 | writetoEEPROM(20, Pot3_Save); 930 | 931 | Check_7 = false; 932 | } 933 | 934 | if ((millis() - save_timer_division_4 > save_time_division) && (Check_8 == true)) { 935 | EEPROM.write(11, constrain(V4,0,255)); 936 | writetoEEPROM(22, Pot4_Save); 937 | 938 | Check_8 = false; 939 | } 940 | 941 | 942 | 943 | 944 | if ((millis() - save_timer_division_5 > save_time_division) && (Check_9 == true)) { //Save when Fine Division has changed and Save Time Has Expired 945 | EEPROM.write(8, constrain(V1,0,255)); 946 | writetoEEPROM(16, Pot1_Save); 947 | 948 | Check_9 = false; 949 | } 950 | 951 | if ((millis() - save_timer_division_6 > save_time_division) && (Check_10 == true)) { 952 | EEPROM.write(9, constrain(V2,0,255)); 953 | writetoEEPROM(18, Pot2_Save); 954 | 955 | Check_10 = false; 956 | } 957 | 958 | if ((millis() - save_timer_division_7 > save_time_division) && (Check_11 == true)) { 959 | EEPROM.write(10, constrain(V3,0,255)); 960 | writetoEEPROM(20, Pot3_Save); 961 | 962 | Check_11 = false; 963 | } 964 | 965 | if ((millis() - save_timer_division_8 > save_time_division) && (Check_12 == true)) { 966 | EEPROM.write(11, constrain(V4,0,255)); 967 | writetoEEPROM(22, Pot4_Save); 968 | 969 | Check_12 = false; 970 | } 971 | 972 | 973 | 974 | 975 | 976 | 977 | if ((millis() - save_timer_random_1 > save_time_random) && (Check_17 == true)) { //Save when Random has changed and Save Time Has Expired 978 | EEPROM.write(12, RND1); 979 | writetoEEPROM(16, Pot1_Save); 980 | 981 | Check_17 = false; 982 | } 983 | 984 | if ((millis() - save_timer_random_2 > save_time_random) && (Check_18 == true)) { 985 | EEPROM.write(13, RND2); 986 | writetoEEPROM(18, Pot2_Save); 987 | 988 | Check_18 = false; 989 | } 990 | 991 | if ((millis() - save_timer_random_3 > save_time_random) && (Check_19 == true)) { 992 | EEPROM.write(14, RND3); 993 | writetoEEPROM(20, Pot3_Save); 994 | 995 | Check_19 = false; 996 | } 997 | 998 | if ((millis() - save_timer_random_4 > save_time_random) && (Check_20 == true)) { 999 | EEPROM.write(15, RND4); 1000 | writetoEEPROM(22, Pot4_Save); 1001 | 1002 | Check_20 = false; 1003 | } 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | if ((millis() - save_timer_swing_1 > save_time_swing) && (Check_21 == true)) { //Save when Swing has changed and Save Time Has Expired 1010 | EEPROM.write(0, S1); 1011 | writetoEEPROM(16, Pot1_Save); 1012 | 1013 | Check_21 = false; 1014 | } 1015 | 1016 | if ((millis() - save_timer_swing_2 > save_time_swing) && (Check_22 == true)) { 1017 | EEPROM.write(1, S2); 1018 | writetoEEPROM(18, Pot2_Save); 1019 | 1020 | Check_22 = false; 1021 | } 1022 | 1023 | if ((millis() - save_timer_swing_3 > save_time_swing) && (Check_23 == true)) { 1024 | EEPROM.write(2, S3); 1025 | writetoEEPROM(20, Pot3_Save); 1026 | 1027 | Check_23 = false; 1028 | } 1029 | 1030 | if ((millis() - save_timer_swing_4 > save_time_swing) && (Check_24 == true)) { 1031 | EEPROM.write(3, S4); 1032 | writetoEEPROM(22, Pot4_Save); 1033 | 1034 | Check_24 = false; 1035 | } 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | 1044 | 1045 | 1046 | 1047 | 1048 | 1049 | if ((clock_timer_1 > 0) && (millis() - clock_timer_1 > Pulse_Length + D1 + s1 )) { // Set Master Clock States low after Pulse_Lenghts Time 1050 | MCS_1 = false; 1051 | clock_timer_1 = 0; 1052 | } 1053 | 1054 | if ((clock_timer_2 > 0) && (millis() - clock_timer_2 > Pulse_Length + D2 + s2 )) { 1055 | MCS_2 = false; 1056 | clock_timer_2 = 0; 1057 | } 1058 | 1059 | if ((clock_timer_3 > 0) && (millis() - clock_timer_3 > Pulse_Length + D3 + s3 )) { 1060 | MCS_3 = false; 1061 | clock_timer_3 = 0; 1062 | } 1063 | 1064 | if ((clock_timer_4 > 0) && (millis() - clock_timer_4 > Pulse_Length + D4 + s4 )) { 1065 | MCS_4 = false; 1066 | clock_timer_4 = 0; 1067 | } 1068 | 1069 | 1070 | 1071 | 1072 | 1073 | if ((reset_timer_1 > 0) && (millis() - reset_timer_1 > Pulse_Length_Reset + D1 + s1)) { // Set Master Reset States low after Pulse_Lenghts Time 1074 | MCS_5 = false; 1075 | reset_timer_1 = 0; 1076 | } 1077 | 1078 | if ((reset_timer_2 > 0) && (millis() - reset_timer_2 > Pulse_Length_Reset + D2 + s2)) { 1079 | MCS_6 = false; 1080 | reset_timer_2 = 0; 1081 | } 1082 | 1083 | if ((reset_timer_3 > 0) && (millis() - reset_timer_3 > Pulse_Length_Reset + D3 + s3)) { 1084 | MCS_7 = false; 1085 | reset_timer_3 = 0; 1086 | } 1087 | 1088 | if ((reset_timer_4 > 0) && (millis() - reset_timer_4 > Pulse_Length_Reset + D4 + s4)) { 1089 | MCS_8 = false; 1090 | reset_timer_4 = 0; 1091 | } 1092 | 1093 | 1094 | 1095 | 1096 | if ((master_timer > 0) && (millis() - master_timer > Pulse_Length + s4)) { 1097 | MCS = false; 1098 | master_timer = 0; 1099 | } 1100 | 1101 | 1102 | 1103 | 1104 | 1105 | 1106 | 1107 | 1108 | if (((MCS_1 == true) && (millis() - clock_timer_1 >= D1 + s1)) && (rndcheck1 == false)) { //Set Clockpins HIGH or LOW with Delays 1109 | rndcheck1 = true; 1110 | rnd1 = random(1,100); 1111 | 1112 | if (rnd1 <= RND1) { 1113 | digitalWrite(CLOCK_1, HIGH); 1114 | } 1115 | 1116 | } 1117 | else if (MCS_1 == false) { 1118 | digitalWrite(CLOCK_1, LOW); 1119 | rndcheck1 = false; 1120 | } 1121 | 1122 | 1123 | 1124 | if (((MCS_2 == true) && (millis() - clock_timer_2 >= D2 + s2)) && (rndcheck2 == false)) { 1125 | rndcheck2 = true; 1126 | rnd2 = random(1,100); 1127 | 1128 | if (rnd2 <= RND2) { 1129 | digitalWrite(CLOCK_2, HIGH); 1130 | } 1131 | 1132 | } 1133 | else if (MCS_2 == false) { 1134 | digitalWrite(CLOCK_2, LOW); 1135 | rndcheck2 = false; 1136 | } 1137 | 1138 | 1139 | 1140 | if (((MCS_3 == true) && (millis() - clock_timer_3 >= D3 + s3)) && (rndcheck3 == false)) { 1141 | rndcheck3 = true; 1142 | rnd3 = random(1,100); 1143 | 1144 | if (rnd3 <= RND3) { 1145 | digitalWrite(CLOCK_3, HIGH); 1146 | } 1147 | 1148 | } 1149 | else if (MCS_3 == false) { 1150 | digitalWrite(CLOCK_3, LOW); 1151 | rndcheck3 = false; 1152 | } 1153 | 1154 | 1155 | 1156 | if (((MCS_4 == true) && (millis() - clock_timer_4 >= D4 + s4)) && (rndcheck4 == false)) { 1157 | rndcheck4 = true; 1158 | rnd4 = random(1,100); 1159 | 1160 | if (rnd4 <= RND4) { 1161 | digitalWrite(CLOCK_4, HIGH); 1162 | } 1163 | 1164 | } 1165 | else if (MCS_4 == false) { 1166 | digitalWrite(CLOCK_4, LOW); 1167 | rndcheck4 = false; 1168 | } 1169 | 1170 | 1171 | 1172 | 1173 | 1174 | 1175 | 1176 | 1177 | if ((MCS_5 == true) && (millis() - reset_timer_1 >= D1 + s1)) { //Set Reset Pins High or Low (Only used for LED but could be used to send reset triggers out through jacks!!!) 1178 | digitalWrite(RESET_1, HIGH); 1179 | } 1180 | else { 1181 | digitalWrite(RESET_1, LOW); 1182 | } 1183 | 1184 | 1185 | 1186 | if ((MCS_6 == true) && (millis() - reset_timer_2 >= D2 + s2)) { 1187 | digitalWrite(RESET_2, HIGH); 1188 | } 1189 | else { 1190 | digitalWrite(RESET_2, LOW); 1191 | } 1192 | 1193 | 1194 | 1195 | if ((MCS_7 == true) && (millis() - reset_timer_3 >= D3 + s3)) { 1196 | digitalWrite(RESET_3, HIGH); 1197 | } 1198 | else { 1199 | digitalWrite(RESET_3, LOW); 1200 | } 1201 | 1202 | 1203 | 1204 | if ((MCS_8 == true) && (millis() - reset_timer_4 >= D4 + s4)) { 1205 | digitalWrite(RESET_4, HIGH); 1206 | } 1207 | else { 1208 | digitalWrite(RESET_4, LOW); 1209 | } 1210 | 1211 | 1212 | 1213 | 1214 | 1215 | 1216 | 1217 | 1218 | 1219 | 1220 | //MIDI EVENT 1221 | 1222 | 1223 | midiEventPacket_t rx = MidiUSB.read(); // listen for new MIDI messages 1224 | switch (rx.byte1) { 1225 | 1226 | case 0xF8: //Clock 1227 | 1228 | 1229 | 1230 | if (millis() > clock_timeout_1 + 300) clock_count_1 = 0; // Prevents Clock from starting in between quarter notes after clock is restarted! 1231 | clock_timeout_1 = millis(); 1232 | 1233 | if (millis() > clock_timeout_2 + 300) clock_count_2 = 0; 1234 | clock_timeout_2 = millis(); 1235 | 1236 | if (millis() > clock_timeout_3 + 300) clock_count_3 = 0; 1237 | clock_timeout_3 = millis(); 1238 | 1239 | if (millis() > clock_timeout_4 + 300) clock_count_4 = 0; 1240 | clock_timeout_4 = millis(); 1241 | 1242 | 1243 | if (millis() > reset_timeout_1 + 300) reset_count_1 = 0; // Prevents Reset from starting in between quarter notes after clock is restarted! 1244 | reset_timeout_1 = millis(); 1245 | 1246 | if (millis() > reset_timeout_2 + 300) reset_count_2 = 0; 1247 | reset_timeout_2 = millis(); 1248 | 1249 | if (millis() > reset_timeout_3 + 300) reset_count_3 = 0; 1250 | reset_timeout_3 = millis(); 1251 | 1252 | if (millis() > reset_timeout_4 + 300) reset_count_4 = 0; 1253 | reset_timeout_4 = millis(); 1254 | 1255 | 1256 | 1257 | if (millis() > master_timeout + 300) master_count = 0; 1258 | master_timeout = millis(); 1259 | 1260 | 1261 | 1262 | 1263 | 1264 | 1265 | 1266 | 1267 | if (clock_count_1 == 0) { //Clock Counter gets pushed +1 and Master Clock State gets enabled 1268 | MCS_1 = true; 1269 | clock_timer_1 = millis(); 1270 | } 1271 | clock_count_1++; 1272 | 1273 | if (clock_count_2 == 0) { 1274 | MCS_2 = true; 1275 | clock_timer_2 = millis(); 1276 | } 1277 | clock_count_2++; 1278 | 1279 | if (clock_count_3 == 0) { 1280 | MCS_3 = true; 1281 | clock_timer_3 = millis(); 1282 | } 1283 | clock_count_3++; 1284 | 1285 | if (clock_count_4 == 0) { 1286 | MCS_4 = true; 1287 | clock_timer_4 = millis(); 1288 | } 1289 | clock_count_4++; 1290 | 1291 | 1292 | 1293 | if (reset_count_1 == 0) { //Clock Counter gets pushed +1 and Master Reset State gets enabled 1294 | MCS_5 = true; 1295 | reset_timer_1 = millis(); 1296 | } 1297 | reset_count_1++; 1298 | 1299 | if (reset_count_2 == 0) { 1300 | MCS_6 = true; 1301 | reset_timer_2 = millis(); 1302 | } 1303 | reset_count_2++; 1304 | 1305 | if (reset_count_3 == 0) { 1306 | MCS_7 = true; 1307 | reset_timer_3 = millis(); 1308 | } 1309 | reset_count_3++; 1310 | 1311 | if (reset_count_4 == 0) { 1312 | MCS_8 = true; 1313 | reset_timer_4 = millis(); 1314 | } 1315 | reset_count_4++; 1316 | 1317 | 1318 | 1319 | if (master_count == 0) { 1320 | MCS = true; 1321 | master_timer = millis(); 1322 | } 1323 | master_count++; 1324 | 1325 | 1326 | 1327 | 1328 | 1329 | 1330 | 1331 | 1332 | 1333 | if ((clock_count_1 >= V1) && (V1 <= 254)) { // Reset Clock Counter through Divisions: MIDI timing clock sends 24 pulses per quarter note. Send pulse only once every 12 pulses 1334 | clock_count_1 = 0; 1335 | } 1336 | 1337 | if ((clock_count_2 >= V2) && (V2 <= 254)) { 1338 | clock_count_2 = 0; 1339 | } 1340 | 1341 | if ((clock_count_3 >= V3) && (V3 <= 254)) { 1342 | clock_count_3 = 0; 1343 | } 1344 | 1345 | if ((clock_count_4 >= V4) && (V4 <= 254)) { 1346 | clock_count_4 = 0; 1347 | } 1348 | 1349 | 1350 | 1351 | 1352 | if ((reset_count_1 >= R1) && (R1 <= 254)) { // Reset Clock Counter through Divisions 1353 | reset_count_1 = 0; 1354 | clock_count_1 = 0; 1355 | } 1356 | 1357 | if ((reset_count_2 >= R2) && (R2 <= 254)) { 1358 | reset_count_2 = 0; 1359 | clock_count_2 = 0; 1360 | } 1361 | 1362 | if ((reset_count_3 >= R3) && (R3 <= 254)) { 1363 | reset_count_3 = 0; 1364 | clock_count_3 = 0; 1365 | } 1366 | 1367 | if ((reset_count_4 >= R4) && (R4 <= 254)) { 1368 | reset_count_4 = 0; 1369 | clock_count_4 = 0; 1370 | } 1371 | 1372 | 1373 | 1374 | 1375 | if (master_count >= 12) { 1376 | master_count = 0; 1377 | } 1378 | 1379 | 1380 | 1381 | 1382 | 1383 | 1384 | 1385 | break; 1386 | } 1387 | 1388 | 1389 | } 1390 | 1391 | 1392 | 1393 | //Functions 1394 | 1395 | 1396 | void writetoEEPROM(int address, int number) //Write Int to EEPROM 1397 | { 1398 | EEPROM.write(address, number >> 8); 1399 | EEPROM.write(address + 1, number & 0xFF); 1400 | } 1401 | -------------------------------------------------------------------------------- /IMG_4367.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luislutz/Arduino-MIDI-Clocker/13f5c3bfaf783b24d4901429fb9d86d53e4d84d1/IMG_4367.jpg -------------------------------------------------------------------------------- /Pictures MIDI Clocker/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luislutz/Arduino-MIDI-Clocker/13f5c3bfaf783b24d4901429fb9d86d53e4d84d1/Pictures MIDI Clocker/1.jpg -------------------------------------------------------------------------------- /Pictures MIDI Clocker/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luislutz/Arduino-MIDI-Clocker/13f5c3bfaf783b24d4901429fb9d86d53e4d84d1/Pictures MIDI Clocker/2.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arduino-MIDI-Clocker 2 | Arduino based USB Midi to clock sync converter, Clock divider and Trigger sequencer 3 | 4 | 5 | Its main purpose was to sync my small synths and pocket operators which dont have usb midi, but it turned out to be quite usable for directly triggering drums in a modular rack or drum machine. Pink LEDs are the triggers going to the 4 outputs. Green LEDs are individual resets for each channel. 6 | Thera are 3 shift buttons (delay, reset and subdivision) to acces different parameters with the knobs: 7 | Mode 1 (not holding any button): 8 | The Knobs change the division of the incoming midi clock in powers of two (half time double time, quadruple time) 9 | Mode 2 (holding subdiv button): 10 | This gives acces to other divisions of the midi clock. The Knobs change the clock division with odd multiples in between. 11 | Mode 3 (holding reset button): 12 | Lets you change the reset for each channel to 1 16th1, 1 eights , 1 quarter, 1 half, 1 bar, 4 bars, none) 13 | Mode 4 (holding delay button): 14 | The Knobs acces indivisual time delays the each channel from 0-50ms. This is for syncing multiple devices with a DAW. Im setting my midi clock sync output in ableton to be 50 ms early (-50ms). Then i have individual control over the latency for Gear that might be synced or triggered by one of the channels! 15 | The values only get changed if the corresponding mode is on and the pot is moved a certain amount, and gets saved 5 seconds afterwards (all of these prameters like pulse duration can easily be modified in the code) to have the values the same after a new powerup! 16 | The toggle switches are for breaking the ground connection to the triggered device to elimimate ground loop of needed. 17 | BOM: 18 | Arduino Pro Micro 19 | 4 Jacks 20 | 4 Pots (i used b50k but it doesnt really matter) 21 | 8 LEDs 22 | 8 Resistors (>=470R ) 23 | 3 push buttons 24 | 4 toggle switches 25 | --------------------------------------------------------------------------------