updated libaries, debug mode for MIDI libary, commented bambatu.ino sketch
This commit is contained in:
parent
89c20bb101
commit
d053ca9637
@ -7,65 +7,73 @@
|
||||
|
||||
MIDI Midi;
|
||||
|
||||
//MCP23017 I2C addresses 0,1,3 and 4 (2 is unused yet)
|
||||
INPUT_MCP23017 input_MCP23017_0;
|
||||
INPUT_MCP23017 input_MCP23017_1;
|
||||
INPUT_MCP23017 input_MCP23017_3;
|
||||
INPUT_MCP23017 input_MCP23017_4;
|
||||
|
||||
//three 74HC4051 on analog pins A0,A1,A2; select on digital pins 8,9,10
|
||||
INPUT_74HC4051 input_4051_A0;
|
||||
INPUT_74HC4051 input_4051_A1;
|
||||
INPUT_74HC4051 input_4051_A2;
|
||||
|
||||
ROTARY_ENCODER rotary_encoder_jogwheel_left(rotary_encoder_jogwheel_left_inc, rotary_encoder_jogwheel_left_dec);
|
||||
ROTARY_ENCODER rotary_encoder_jogwheel_right(rotary_encoder_jogwheel_right_inc, rotary_encoder_jogwheel_right_dec);
|
||||
ROTARY_ENCODER rotary_encoder_browse(rotary_encoder_browse_inc,rotary_encoder_browse_dec);
|
||||
//three rotary encoders connected to input_MCP23017_1 and input_MCP23017_3
|
||||
ROTARY_ENCODER rotary_encoder_jogwheel_left(rotary_encoder_jogwheel_left_inc, rotary_encoder_jogwheel_left_dec); //input_MCP23017_1 pins 6 and 7
|
||||
ROTARY_ENCODER rotary_encoder_jogwheel_right(rotary_encoder_jogwheel_right_inc, rotary_encoder_jogwheel_right_dec); //input_MCP23017_3 pins 9 and 1
|
||||
ROTARY_ENCODER rotary_encoder_browse(rotary_encoder_browse_inc,rotary_encoder_browse_dec); //input_MCP23017_3 pins 5 and 6
|
||||
|
||||
|
||||
void setup() {
|
||||
//initialize MIDI
|
||||
Midi.begin();
|
||||
//initialize MCP23017s
|
||||
input_MCP23017_0.begin(0,digitalCallback);
|
||||
input_MCP23017_1.begin(1,digitalCallback1);
|
||||
input_MCP23017_3.begin(3,digitalCallback3);
|
||||
input_MCP23017_4.begin(4,digitalCallback);
|
||||
|
||||
//initialize 74HC4051s
|
||||
input_4051_A0.begin(A0,8,9,10,analogCallback);
|
||||
input_4051_A1.begin(A1,8,9,10,analogCallback);
|
||||
input_4051_A2.begin(A2,8,9,10,analogCallback);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
//loop MCP23017s for callbacks
|
||||
input_MCP23017_0.loop();
|
||||
input_MCP23017_1.loop();
|
||||
input_MCP23017_3.loop();
|
||||
input_MCP23017_4.loop();
|
||||
//loop 74HC4051s for callback
|
||||
input_4051_A0.loop();
|
||||
input_4051_A1.loop();
|
||||
input_4051_A2.loop();
|
||||
}
|
||||
|
||||
|
||||
//callback for analog, sends CC message with unique controller id
|
||||
void analogCallback(int id, int pin, int value) {
|
||||
Midi.controlChange((id-A0) * 8 + pin,value);
|
||||
}
|
||||
|
||||
//default callback for buttons, sends note-on/off message with unique note value
|
||||
void digitalCallback(int id, int pin, int value) {
|
||||
if (value == HIGH)
|
||||
Midi.noteOn(id * 16 + pin, MIDI_MAX_DATA);
|
||||
else Midi.noteOff(id * 16 + pin);
|
||||
}
|
||||
|
||||
|
||||
//callback for input_MCP23017_1, checks for rotary_encoder_jogwheel_left, otherwise default callback
|
||||
void digitalCallback1(int id, int pin, int value) {
|
||||
if (pin == 6)
|
||||
rotary_encoder_jogwheel_left.setPinA(value);
|
||||
if (pin == 7)
|
||||
rotary_encoder_jogwheel_left.setPinB(value);
|
||||
if (pin != 6 && pin !=7) {
|
||||
if (value == HIGH)
|
||||
Midi.noteOn(id * 16 + pin, MIDI_MAX_DATA);
|
||||
else Midi.noteOff(id * 16 + pin);
|
||||
}
|
||||
if (pin != 6 && pin !=7)
|
||||
digitalCallback(id,pin,value);
|
||||
}
|
||||
|
||||
//callback for input_MCP23017_3, checks for rotary_encoder_jogwheel_right and rotary_encoder_browse, otherwise default callback
|
||||
void digitalCallback3(int id, int pin, int value) {
|
||||
if (pin == 9)
|
||||
rotary_encoder_jogwheel_right.setPinA(value);
|
||||
@ -75,37 +83,39 @@ void digitalCallback3(int id, int pin, int value) {
|
||||
rotary_encoder_browse.setPinA(value);
|
||||
if (pin == 5)
|
||||
rotary_encoder_browse.setPinB(value);
|
||||
if (pin!= 9 && pin != 10 && pin != 6 && pin != 5){
|
||||
if (value == HIGH)
|
||||
Midi.noteOn(id * 16 + pin, MIDI_MAX_DATA);
|
||||
else Midi.noteOff(id * 16 + pin);
|
||||
}
|
||||
if (pin!= 9 && pin != 10 && pin != 6 && pin != 5)
|
||||
digitalCallback(id,pin,value);
|
||||
}
|
||||
|
||||
//left jogwheel
|
||||
//left jogwheel, sends CC message on controller id 0x7A with value 65 (increment)
|
||||
void rotary_encoder_jogwheel_left_inc() {
|
||||
Midi.controlChange(MIDI_MAX_DATA-5,65);
|
||||
}
|
||||
|
||||
//left jogwheel, sends CC message on controller id 0x7A with value 63 (decrement)
|
||||
void rotary_encoder_jogwheel_left_dec() {
|
||||
Midi.controlChange(MIDI_MAX_DATA-5,63);
|
||||
}
|
||||
|
||||
//right jogwheel
|
||||
|
||||
//right jogwheel, sends CC message on controller id 0x79 with value 65 (increment)
|
||||
void rotary_encoder_jogwheel_right_inc() {
|
||||
Midi.controlChange(MIDI_MAX_DATA-6,65);
|
||||
}
|
||||
|
||||
//right jogwheel, sends CC message on controller id 0x79 with value 63 (decrement)
|
||||
void rotary_encoder_jogwheel_right_dec() {
|
||||
Midi.controlChange(MIDI_MAX_DATA-6,63);
|
||||
}
|
||||
|
||||
//Browse
|
||||
|
||||
//browse, sends note-on/off signal with note 0x36 [equals to default digital callback note] (increment)
|
||||
void rotary_encoder_browse_inc() {
|
||||
Midi.noteOn(3 * 16 + 6, MIDI_MAX_DATA);
|
||||
Midi.noteOff(3 * 16 + 6);
|
||||
}
|
||||
|
||||
//browse, sends note-on/off signal with note 0x35 [equals to default digital callback note] (decrement)
|
||||
void rotary_encoder_browse_dec() {
|
||||
Midi.noteOn(3 * 16 + 5, MIDI_MAX_DATA);
|
||||
Midi.noteOff(3 * 16 + 5);
|
||||
|
@ -47,10 +47,9 @@ void INPUT_74HC4051::loop() {
|
||||
digitalWrite(_s0, r0);
|
||||
digitalWrite(_s1, r1);
|
||||
digitalWrite(_s2, r2);
|
||||
//not sure if nessesary
|
||||
//delayMicroseconds(10);
|
||||
//divide by 8 to get value beetween 0-127 for MIDI
|
||||
value = analogRead(_analog) / 8;
|
||||
if (_value[pin] < value - INPUT_74HC4051_TOLERANCE || _value[pin] > value + INPUT_74HC4051_TOLERANCE) {
|
||||
if (_value[pin] < value || _value[pin] > value) {
|
||||
_value[pin] = value;
|
||||
(*_callbackFunction)(_analog,pin,value);
|
||||
}
|
||||
|
@ -13,8 +13,6 @@
|
||||
#ifndef bombatuino_INPUT_74HC4051_h
|
||||
#define bombatuino_INPUT_74HC4051_h
|
||||
|
||||
#define INPUT_74HC4051_TOLERANCE 0 /**< I/O DIRECTION REGISTER PORT A - Controls the direction of the data I/O. */
|
||||
|
||||
#if !defined(CallbackFunction)
|
||||
/**
|
||||
* callback function
|
||||
|
@ -2,7 +2,11 @@
|
||||
#include "bombatuino_MIDI.h"
|
||||
|
||||
void MIDI::begin(int channel) {
|
||||
#ifdef DEBUG
|
||||
Serial.begin(9600);
|
||||
#else
|
||||
Serial.begin(31250);
|
||||
#endif
|
||||
//if given channel is not valid, set default channel to 1
|
||||
if (channel > MIDI_MAX_CHANNEL)
|
||||
channel = MIDI_DEFAULT_CHANNEL;
|
||||
@ -21,39 +25,76 @@ bool MIDI::message(int status, int data, int data2, int channel) {
|
||||
//check if channel is valid
|
||||
if (channel > MIDI_MAX_CHANNEL) return false;
|
||||
//write bytes to serial
|
||||
#ifdef DEBUG
|
||||
Serial.print("status: ");
|
||||
Serial.print(status+channel);
|
||||
Serial.print(" data: ");
|
||||
Serial.print(data);
|
||||
#else
|
||||
Serial.write(status+channel);
|
||||
Serial.write(data);
|
||||
#endif
|
||||
//check if second data byte should be send
|
||||
if (status != MIDI_PROGRAMM_CHANGE && status != MIDI_CHANNEL_PRESSURE)
|
||||
if (status != MIDI_PROGRAMM_CHANGE && status != MIDI_CHANNEL_PRESSURE) {
|
||||
#ifdef DEBUG
|
||||
Serial.print(" data2: ");
|
||||
Serial.print(data2);
|
||||
#else
|
||||
Serial.write(data2);
|
||||
#endif
|
||||
}
|
||||
#ifdef DEBUG
|
||||
Serial.println();
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MIDI::noteOff(int note, int velocity, int channel) {
|
||||
#ifdef DEBUG
|
||||
Serial.print(" noteOff ");
|
||||
#endif
|
||||
return message(MIDI_NOTE_OFF,note,velocity,channel);
|
||||
}
|
||||
|
||||
bool MIDI::noteOn(int note, int velocity, int channel) {
|
||||
#ifdef DEBUG
|
||||
Serial.print(" noteOn ");
|
||||
#endif
|
||||
return message(MIDI_NOTE_ON,note,velocity,channel);
|
||||
}
|
||||
|
||||
bool MIDI::polyphonicKeyPressure(int note, int velocity, int channel) {
|
||||
#ifdef DEBUG
|
||||
Serial.print(" polyphonicKeyPressure ");
|
||||
#endif
|
||||
return message(MIDI_POLYPHONIC_KEY_PRESSURE,note,velocity,channel);
|
||||
}
|
||||
|
||||
bool MIDI::controlChange(int controller, int value, int channel) {
|
||||
#ifdef DEBUG
|
||||
Serial.print(" controlChange ");
|
||||
#endif
|
||||
return message(MIDI_CONTROL_CHANGE,controller,value,channel);
|
||||
}
|
||||
|
||||
bool MIDI::programChange(int programm, int channel) {
|
||||
#ifdef DEBUG
|
||||
Serial.print(" programChange ");
|
||||
#endif
|
||||
return message(MIDI_PROGRAMM_CHANGE,programm,0,channel);
|
||||
}
|
||||
|
||||
bool MIDI::channelPressure(int pressure, int channel) {
|
||||
#ifdef DEBUG
|
||||
Serial.print(" channelPressure ");
|
||||
#endif
|
||||
return message(MIDI_CHANNEL_PRESSURE,pressure,0,channel);
|
||||
}
|
||||
|
||||
bool MIDI::pitchWheelChange(int last, int most, int channel) {
|
||||
#ifdef DEBUG
|
||||
Serial.print(" pitchWheelChange ");
|
||||
#endif
|
||||
return message(MIDI_PITCH_WHEEL_CHANGE,last,most,channel);
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,9 @@
|
||||
*
|
||||
* */
|
||||
|
||||
//uncomment for debugging
|
||||
//#define DEBUG
|
||||
|
||||
#ifndef bombatuino_MIDI_h
|
||||
#define bombatuino_MIDI_h
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
* @date February, 2013
|
||||
*
|
||||
* @brief arduino library for handling a rotary encoder
|
||||
* @brief arduino library for handling a rotary encoder (simplified)
|
||||
*
|
||||
* library is for specialiced use: increment- and decrement-functions are called on change of pin A.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user