-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhb_mp-100-for-headrush-gb-via-arduino.ino
77 lines (67 loc) · 1.99 KB
/
hb_mp-100-for-headrush-gb-via-arduino.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <MIDI.h>
#include <Arduino_DebugUtils.h>
// Create and bind the MIDI interface to the default hardware Serial port
MIDI_CREATE_DEFAULT_INSTANCE();
// uncomment this for debugging via the LED
//#define MYDEBUG 1
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(19200);
Debug.setDebugLevel(DBG_VERBOSE);
Debug.print(DBG_WARNING, "starting the CC filter");
blinkShortly();
MIDI.begin(MIDI_CHANNEL_OMNI); // Listen to all incoming messages
MIDI.turnThruOff();
MIDI.setHandleControlChange(ccFunc);
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
void ccFunc(byte channel, byte number, byte value) {
// re-map the value from 127 to 0 for HB MP100 -> Headrush GB
if (value == 127) {
// down
MIDI.sendControlChange(number, 127, channel);
// up
MIDI.sendControlChange(number, 0, channel);
} else {
// pass through
MIDI.sendControlChange(number, value, channel);
}
#ifdef MYDEBUG
blinkNumberInReverseOrder(channel);
blinkNumberInReverseOrder(number);
blinkNumberInReverseOrder(value);
#else
blinkShortly();
#endif
}
void blinkShortly() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(LED_BUILTIN, LOW);
}
// use when debugging
void blinkNumberInReverseOrder(byte number) {
int delayMs = 300;
while (number > 0) {
byte lastDigit = number % 10;
number = number / 10;
if (lastDigit == 0) {
delayMs = 100;
lastDigit = 10;
} else {
delayMs = 300;
}
for (byte i = 0; i < lastDigit; i++) {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(delayMs); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(delayMs);
}
delay(1000);
}
delay(3000);
}
void loop() {
MIDI.read();
}