     counter++;
     if (counter == 24) {
       counter = 0;
-      digitalWrite(redLed, HIGH);
+      digitalWrite(bpmLed, HIGH);
     }
     if (counter == 23) {
-      digitalWrite(redLed, HIGH);
+      digitalWrite(bpmLed, HIGH);
     }
 
     if (counter == 6) {
-      digitalWrite(redLed, LOW);
+      digitalWrite(bpmLed, LOW);
     }
   }
 
   if (realtimebyte == START || realtimebyte == CONTINUE) {
     counter = 0;
-    digitalWrite(redLed, HIGH);
+    digitalWrite(bpmLed, HIGH);
   }
 
   if (realtimebyte == STOP) {
-    digitalWrite(redLed, LOW);
+    digitalWrite(bpmLed, LOW);
   }
 }
 

#include "base64/Base64.h"

const int ledPin = 13;
byte counter;
const byte CLOCK = 248;
const byte START = 250;
const byte CONTINUE = 251;
const byte STOP = 252;
const int redLed = 1;

void OnNoteOn(byte channel, byte note, byte velocity)
{


}

void setupButtons() {
  for (byte i = 0; i < numberOfChannelButtons; i++) {
    pinMode(channelButtonStart + i, INPUT_PULLUP);
    channelButtons[i].attach(channelButtonStart + i);
    channelButtons[i].interval(10);
    channelButtonStates[i] = false;
    channelButtonDown[i] = false;
  }
}

void setupLeds() {
  pinMode(ledPin, OUTPUT);
  pinMode(bpmLed, OUTPUT);
  for (byte i = 0; i < numberOfChannelButtons; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
}


void setup()
{
  setupButtons();
  setupLeds();

  Serial.begin(9600);
  usbMIDI.setHandleNoteOff(OnNoteOff);
  usbMIDI.setHandleNoteOn(OnNoteOn);
  usbMIDI.setHandleRealTimeSystem(RealTimeSystem);
  usbMIDI.setHandleSysEx(SystemExclusiveMessage);

  ledTest();

  Serial.println("start");
}

void ledTest() {
  ledTest(ledPin);
  ledTest(bpmLed);
  for (byte i = 0; i < numberOfChannelButtons; i++) {
    ledTest(ledPins[i]);
    //    digitalWrite(channelButtonLedStart +i,HIGH);
  }
}

void ledTest(byte pin) {
  digitalWrite(pin, HIGH);
  delay(200);
  digitalWrite(pin, LOW);
  delay(200);
}

void updateButtons() {
  for (byte i = 0; i < numberOfChannelButtons; i++) {
    if (channelButtons[i].update()) {
      if (channelButtons[i].read() == LOW) {
        channelButtonDown[i] = true;
      } else if (channelButtonDown[i]) {
        channelButtonStates[i] = 1 - channelButtonStates[i];
        channelButtonDown[i] = false;
        if (channelButtonStates[i]) {
          digitalWrite(ledPins[i], HIGH);
        } else {
          digitalWrite(ledPins[i], LOW);
        }
      }
    }
  }
}

void loop()
{
  usbMIDI.read();
  updateButtons();
}

void RealTimeSystem(byte realtimebyte) {
