 
 boolean led_state;
 char tmp_str[256];
+
+boolean serial_over_midi;
+String send_buffer;
 
 struct trigger {
   long t;  // time of latest occurrence in microseconds

      // This blocks all other execution for about 1 second
      run_brightness_curve();
    } else {
      Serial.print("Unknown command:");
      Serial.println(cmd);
    }
  }


  led_state = !led_state;
}

void send(char c) { send_buffer += c; }
void send(String s) { send_buffer += s; }

void send(long l) {
  char s[32];
  sprintf(s, "%ld", l);
  send(s);
}

void send(unsigned long l) {
  char s[32];
  sprintf(s, "%lud", l);
  send(s);
}

void send(short i) { send((long)i); }
void send(int i) { send((long)i); }
void send(unsigned short i) { send ((unsigned long)i); }
void send(unsigned int i) { send ((unsigned int)i); }

void send_now() {
  if (serial_over_midi) {
    usbMIDI.sendSysEx(send_buffer.length(), (const uint8_t *)send_buffer.c_str());
    usbMIDI.send_now();
    send_buffer = MIDI_SYSEX_BEGIN;
  } else {
    Serial.write(send_buffer.c_str(), send_buffer.length());
    Serial.send_now();
    send_buffer = String();
  }
}

void send_line() {
  if (!serial_over_midi) {
    send('\n');
  } else {
    send(MIDI_SYSEX_END);
  }
  send_now();
}

void send_trigger(struct trigger t) {
  char s[256];
  sprintf(s, "G %c %ld %d %d", t.tag, t.t, t.value, t.count);
  send(s);
  send_line();
}

// flips case for a give char. Unchanged if not in [A-Za-z].
