Skip to content

Instantly share code, notes, and snippets.

@joshnishikawa
Created March 23, 2023 05:56
Show Gist options
  • Save joshnishikawa/2b69829b3e6b8756d61bd39174141130 to your computer and use it in GitHub Desktop.
Save joshnishikawa/2b69829b3e6b8756d61bd39174141130 to your computer and use it in GitHub Desktop.
/*
This example will show how to use a switch and drum to toggle between two
START and STOP real time messages.
*/
#include "MIDIcontroller.h"
byte MIDIchannel = 5;
const int switchPin = 19;
const int drumPin = 14;
const int ledPin = 13; //Set an LED to show the state of the input.
MIDIswitch mySwitch(switchPin, START); // Don't use LATCH
MIDIdrum myDrum(drumPin, 66);
bool state = false;
void setup(){
pinMode(ledPin, OUTPUT);
myDrum.inputRange(10, 700);
myDrum.setSensitivity(99);
myDrum.setWaitTime(30);
}
void loop(){
if ( mySwitch.send() > -1 ){ // no input == -1
state = !state;
if (state) mySwitch.setControlNumber(STOP);
else mySwitch.setControlNumber(START);
}
if ( myDrum.read() > 0 ) { // no input == -1, ignore OFF messages
state = !state;
mySwitch.send(FORCE);
if (state) mySwitch.setControlNumber(STOP);
else mySwitch.setControlNumber(START);
}
digitalWrite(ledPin, state); // LED indicates state
// This prevents crashes that happen when incoming usbMIDI is ignored.
while(usbMIDI.read()){}
// Also uncomment this if compiling for standard MIDI
// while(MIDI.read()){}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment