int tempo = 1000; int tempoPotPin = A17; //int synthNotes[8] = { 60, 62, 64, 65, 67, 69, 71, 72 }; //int drumNotes[8] = { 36, 39, 36, 39, 36, 39, 36, 39 }; int kickNotes[8] = {1, 0, 0, 0, 1, 0, 0, 0}; int clapNotes[8] = {0, 1, 0, 1, 0, 1, 0, 1}; int openhihatNotes[8] = {0, 0, 1, 0, 0, 1, 0, 0}; int closedhihatNotes[8] = {0, 0, 0, 1, 0, 0, 0, 1}; int snareNotes[8] = {0, 0, 0, 0, 1, 0, 0, 0}; int cowbellNotes[8] = {1, 0, 0, 0, 0, 1, 0, 0}; int cymbalNotes[8] = {0, 0, 0, 1, 0, 0, 0, 1}; int tomNotes[8] = {0, 0, 1, 0, 0, 1, 0, 0};

int velocity = 100; int channel = 1;

// int channel = 2;

unsigned long lastStepTime = 0; int currentStep = 0; int totalSteps = 8;

int ledPins[8] = { 5, 6, 7, 8, 9, 10, 11, 12 }; int buttonStates[8] = { LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW }; int lastButtonStates[8] = { LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW }; //int lastButtonState = LOW; // state of the button last time you checked //#include <MIDI.h> //MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);

void setup() { //MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize MIDI with Omni channel (responds to all MIDI channels) //usbMIDI.sendNoteOn(note, velocity, channel); // Replace 'note', 'velocity', and 'channel' with your values

Serial.begin(9600); //make pin 2 an input: pinMode(25, INPUT); pinMode(26, INPUT); pinMode(27, INPUT); pinMode(28, INPUT); pinMode(29, INPUT); pinMode(30, INPUT); pinMode(31, INPUT); pinMode(32, INPUT);

for (int i = 0; i < totalSteps; i++) { pinMode(ledPins[i], OUTPUT); } }

void loop() { updateTempo(); updateSequencer(); updateLeds(); // read the pushbutton: }

void updateTempo() { tempo = map(analogRead(A17), 0, 1023, 50, 1000); }

void onButtonChangeCycleNote(int pin, int step) { buttonStates[step] = digitalRead(pin);

// check if the current button state is different than the last state: if (buttonStates[step] != lastButtonStates[step]) { // do stuff if it is different here if (buttonStates[step] == HIGH) { // Serial.println(step); Serial.print(clapNotes[0]); Serial.print(clapNotes[1]); Serial.print(clapNotes[2]); Serial.print(clapNotes[3]); Serial.print(clapNotes[4]); Serial.print(clapNotes[5]); Serial.print(clapNotes[6]); Serial.println(clapNotes[7]);

  //Serial.println(drumNotes[2]);
  Serial.println("Button was just pressed.");
  //      if (drumNotes[step] == 0) {
  //        drumNotes[step] = 36;
  //      } else if (drumNotes[step] == 36) {
  //        drumNotes[step] = 39;
  //      } else if (drumNotes[step] == 39) {
  //        drumNotes[step] = 0;
  //      }

  //      clapNotes[step] = 1;
  if (clapNotes[step] == 1) {
    clapNotes[step] = 0;
  } else if (clapNotes[step] == 0){
             clapNotes[step] = 1;
  }

}

// save button state for next comparison: lastButtonStates[step] = buttonStates[step]; } }

void updateSequencer() {

if (millis() > lastStepTime + tempo) {

lastStepTime = millis();

currentStep++;
if (currentStep >= totalSteps) {
  currentStep = 0;
}

//Serial.println(currentStep);

if (kickNotes[currentStep] > 0) {
  usbMIDI.sendNoteOn(36, velocity, channel);
}
if (clapNotes[currentStep] > 0) {
  usbMIDI.sendNoteOn(39, velocity, channel);
}
if (openhihatNotes[currentStep] > 0) {
  usbMIDI.sendNoteOn(46, velocity, channel);
}
if (closedhihatNotes[currentStep] > 0) {
  usbMIDI.sendNoteOn(42, velocity, channel);
}
if (snareNotes[currentStep] > 0) {
  usbMIDI.sendNoteOn(38, velocity, channel);
}
if (cowbellNotes[currentStep] > 0) {
  usbMIDI.sendNoteOn(50, velocity, channel);
}
if (cymbalNotes[currentStep] > 0) {
  usbMIDI.sendNoteOn(49, velocity, channel);
}
if (tomNotes[currentStep] > 0) {
  usbMIDI.sendNoteOn(47, velocity, channel);
}

}