Last active
March 9, 2018 16:56
-
-
Save LFSaw/f49334c2ddbaf3c924d13af28de22f84 to your computer and use it in GitHub Desktop.
arduino midi snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <MIDI.h> | |
// set BAUDRATE to non-MIDI standard (as defined in midibridge) | |
struct HairlessMidiSettings : public midi::DefaultSettings | |
{ | |
static const bool UseRunningStatus = false; | |
static const long BaudRate = 115200; // set baudrate | |
}; | |
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, HairlessMidiSettings); | |
void setup() { | |
MIDI.begin(MIDI_CHANNEL_OMNI); // Listen to all incoming messages | |
} | |
void loop() { | |
MIDI.sendControlChange(0, random(0, 127), 1); | |
delay(5); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <MIDI.h> | |
// pin definitions | |
#define IN_PIN A0 | |
struct HairlessMidiSettings : public midi::DefaultSettings | |
{ | |
static const bool UseRunningStatus = false; | |
static const long BaudRate = 115200; | |
}; | |
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, HairlessMidiSettings); | |
int sensorVal; | |
void setup() { | |
MIDI.begin(MIDI_CHANNEL_OMNI); // Listen to all incoming messages | |
} | |
void loop() { | |
sensorVal = analogRead(IN_PIN); | |
MIDI.sendControlChange(0, map(sensorVal, 0, 1023, 0, 127), 1); | |
delay(5); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <MIDI.h> | |
// pin definitions | |
#define IN_PIN A0 | |
struct HairlessMidiSettings : public midi::DefaultSettings | |
{ | |
static const bool UseRunningStatus = false; | |
static const long BaudRate = 115200; | |
}; | |
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, HairlessMidiSettings); | |
int val, oldVal; | |
void setup() { | |
MIDI.begin(MIDI_CHANNEL_OMNI); // Listen to all incoming messages | |
oldVal = -1; // set to impossible value to force initial sending | |
} | |
void loop() { | |
val = analogRead(IN_PIN); | |
val = map(val, 0, 1023, 0, 127); | |
if (val != oldVal) { | |
oldVal = val; // update oldVal | |
MIDI.sendControlChange(0, val, 1); | |
} | |
delay(5); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <MIDI.h> | |
// pin definitions | |
#define IN_PINS {A0, A1, A2, A3} | |
// how many are used | |
#define NUMVALS 3 | |
struct HairlessMidiSettings : public midi::DefaultSettings | |
{ | |
static const bool UseRunningStatus = false; | |
static const long BaudRate = 115200; | |
}; | |
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, HairlessMidiSettings); | |
int vals[NUMVALS], oldVals[NUMVALS]; | |
int inPins[] = IN_PINS; | |
void setup() { | |
MIDI.begin(MIDI_CHANNEL_OMNI); // Listen to all incoming messages | |
for (int i = 0; i < NUMVALS; i++) { | |
oldVals[i] = -1; // set to impossible vals to force initial send | |
} | |
} | |
void loop() { | |
for (int i = 0; i < NUMVALS; i++) { | |
vals[i] = analogRead(inPins[i]); | |
vals[i] = map(vals[i], 0, 1023, 0, 127); | |
if (vals[i] != oldVals[i]) { | |
oldVals[i] = vals[i]; // update oldVal | |
MIDI.sendControlChange(i, vals[i], 1); | |
} | |
} | |
delay(5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment