Update of the bombatuino with a pro micro board with native usb midi support.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.4 KiB

#include <Wire.h>
#include <bombatuino_INPUT_MCP23017.h>
#include <bombatuino_INPUT_74HC4051.h>
#include "MIDIUSB.h"
#define debug true
//MCP23017 I2C addresses 0,1,2,3 and 4
INPUT_MCP23017 input_MCP23017_0;
INPUT_MCP23017 input_MCP23017_1;
INPUT_MCP23017 input_MCP23017_2;
INPUT_MCP23017 input_MCP23017_3;
INPUT_MCP23017 input_MCP23017_4;
//three 74HC4051 on analog pins A1,A2,A3; select on digital pins 7,8,9
INPUT_74HC4051 input_4051_A1;
INPUT_74HC4051 input_4051_A2;
INPUT_74HC4051 input_4051_A3;
int channel = 0;
int velocity = 120;
const uint8_t NO_PINS = 0b00000000;
void setup() {
#ifdef debug
Serial.begin(9600);
#endif
//initialize MCP23017s
input_MCP23017_0.begin(0,digitalCallback);
input_MCP23017_1.begin(1,digitalCallback);
input_MCP23017_2.begin(2,digitalCallback);
input_MCP23017_3.begin(3,digitalCallback);
input_MCP23017_4.begin(4,digitalCallback);
//initialize 74HC4051s
input_4051_A1.begin(A1,7,8,9,analogCallback);
input_4051_A1.setPins(0b00001000);
input_4051_A2.begin(A2,7,8,9,analogCallback);
input_4051_A2.setPins(NO_PINS);
input_4051_A3.begin(A3,7,8,9,analogCallback);
input_4051_A3.setPins(NO_PINS);
}
void loop() {
//loop MCP23017s for callbacks
input_MCP23017_0.loop();
input_MCP23017_1.loop();
input_MCP23017_2.loop();
input_MCP23017_3.loop();
input_MCP23017_4.loop();
//loop 74HC4051s for callback
input_4051_A1.loop();
input_4051_A2.loop();
input_4051_A3.loop();
MidiUSB.flush();
}
//callback for analog, sends CC message with unique controller id
void analogCallback(int id, int pin, int value) {
#ifdef debug
Serial.print("analog");
Serial.print("\tid\t");
Serial.print(id-A0);
Serial.print("\tpin\t");
Serial.print(pin);
Serial.print("\tvalue\t");
Serial.println(value);
#endif
midiEventPacket_t event = {0x0B, 0xB0 | channel, ((id-A0) * 8 + pin), value};
MidiUSB.sendMIDI(event);
}
//default callback for buttons, sends note-on/off message with unique note value
void digitalCallback(int id, int pin, int value) {
#ifdef debug
Serial.print("digital");
Serial.print("\tid\t");
Serial.print(id);
Serial.print("\tpin\t");
Serial.print(pin);
Serial.print("\tvalue\t");
Serial.println(value);
#endif
if (value == HIGH) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, (id * 16 + pin), velocity};
MidiUSB.sendMIDI(noteOn);
} else {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, (id * 16 + pin), 0};
MidiUSB.sendMIDI(noteOff);
}
}