Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

JustDrums added

  • Loading branch information...
commit 34d948827239e28bcfdf27eab43dfc845a6d42b0 1 parent 236b50e
Magnus-G authored
Showing with 211 additions and 0 deletions.
  1. +127 −0 JustDrums/JustDrums.ino
  2. +84 −0 JustDrums/drumPatterns.h
127 JustDrums/JustDrums.ino
View
@@ -0,0 +1,127 @@
+
+// Clock and drum pattern sketches for the Ardcore Expander
+// Feed a clock in "Clock in" for external beat. Set A1 to more than 0 for internal beat.
+// The clock in toggles between D0 and D1 to open and close.
+// Programs are set with A0. 1, 2, 3... etc from CCW to CW
+// 1. Cycle Program
+// 2. Halves Program
+// 3. Divider Program
+// 4. Drum Program Use A3 to set different drum patterns.
+// A2 controls probablility of output for triggers. Set A2 full CCW for no randomization and turn it CW for increased "drop out" of trig outs.
+// There is a 1 second signal as the program is changed.
+// Written by: Magnus Gyllensward
+
+// the drumPatterns.h file must be in the same folder as this file when compiling.
+#include "drumPatterns.h";
+
+const int clkIn = 2; // the digital (clock) input
+const int digPin[2] = {3,4}; // the digital output pins
+const int pinOffset = 5; // the first DAC pin (from 5-12)
+const int trigTime = 10; // triggers are 10 ms.
+
+// variables for interrupt handling of the clock input
+volatile int clkState = LOW;
+
+// randomization/probability
+int randValue = 1023;
+
+// for the on/off switch on clock in
+int inputIsHigh = 0;
+int digState[2] = {LOW, LOW}; // start with both set low
+
+// counting drumloops. see drums.h for all drum patterns
+int drumLoops = 0;
+int drumDivision[6] = {1, 2, 4, 8, 16, 32};
+
+
+// ==================== start of setup() ======================
+
+void setup() {
+ Serial.begin(9600);
+
+ // set up the digital (clock) input
+ pinMode(clkIn, INPUT);
+
+ // set up the digital outputs
+ for (int i=0; i<2; i++) {
+ pinMode(digPin[i], OUTPUT);
+ digitalWrite(digPin[i], LOW);
+ }
+
+ // set up the 8-bit DAC output pins
+ for (int i=0; i<8; i++) {
+ pinMode(pinOffset+i, OUTPUT);
+ digitalWrite(pinOffset+i, LOW);
+ }
+
+ attachInterrupt(0, isr, RISING);
+}
+
+// ==================== start of loop() =======================
+void loop() {
+
+ // go through drum matrix
+ for (int x=1; x<17; x++) { // temporal. start with first beat point...
+ for (int y=1; y<noOfDrumSteps; y++) { // vertical, outputs. start with output 0...
+ randValue = random(0, 1023);
+ if (randValue > analogRead(2)) {
+
+ // set drumProgram
+ int drumProgram = (analogRead(3) / (1023/noOfDrumPrograms)); if (drumProgram > 0) { drumProgram--; } // deal with zero indexing on addressing the array vs the integer declared to set the number.
+
+ digitalWrite(pinOffset+(y-1), drums[drumProgram][y-1][x-1]);
+ delay(1);
+ digitalWrite(pinOffset+(y-1), LOW);
+
+ }
+ }
+
+ delay(1023 - analogRead(1)); // delay after each beat == bpm
+
+ }
+
+
+
+ // every nth time the drumLoop loops, send out a trigger on no 7.
+ drumLoops++;
+
+ if (drumLoops % 2 == 0) {
+ digitalWrite(3, HIGH);
+ digitalWrite(4, LOW);
+ }
+
+ if (drumLoops % 3 == 0) {
+ digitalWrite(4, HIGH);
+ digitalWrite(3, LOW);
+ }
+
+ if (drumLoops % 6 == 0) {
+ digitalWrite(pinOffset+(7), HIGH);
+ delay(1);
+ digitalWrite(pinOffset+(7), LOW);
+ }
+
+// } // end if clock state high
+} // end loop
+
+// =================== convenience routines ===================
+// isr() - quickly handle interrupts from the clock input
+// ------------------------------------------------------
+void isr()
+{
+ // Note: you don't want to spend a lot of time here, because
+ // it interrupts the activity of the rest of your program.
+ // In most cases, you just want to set a variable and get
+ // out.
+ clkState = HIGH;
+}
+
+// dacOutput(byte) - deal with the DAC output
+// -----------------------------------------
+void dacOutput(byte v)
+{
+ PORTB = (PORTB & B11100000) | (v >> 3);
+ PORTD = (PORTD & B00011111) | ((v & B00000111) << 5);
+}
+
+// ===================== end of program =======================
84 JustDrums/drumPatterns.h
View
@@ -0,0 +1,84 @@
+int const noOfMelodyPatterns = 1;
+int melodyPattern[noOfMelodyPatterns][16] = {
+ // 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8
+ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+};
+
+// drums [z][y][x]
+int const noOfDrumPrograms = 8;
+int const noOfDrumSteps = 7;
+int const noOfDrumOutputs = 6;
+int drums[noOfDrumPrograms][noOfDrumOutputs][16] = {
+ { // -1. sequence
+ // 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8
+ {1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0},
+ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+ },
+
+ { // 0. straight
+ // 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8
+ {1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
+ {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0},
+ {1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0}, // synchopation
+ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+ },
+
+ { // 1. double bd start
+ // 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8
+ {1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {1, 0, 0, 0, 1, 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, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1}, // synchopation
+ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+ },
+
+ { // 5.
+ // 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8
+ {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1},
+ {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0},
+ {1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1}, // synchopation
+ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+ },
+
+ { // 6.
+ // 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8
+ {1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0},
+ {0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1},
+ {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0},
+ {1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0}, // synchopation
+ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+ }
+};
+
Please sign in to comment.
Something went wrong with that request. Please try again.