diff --git a/design_files/design.odg b/design_files/design.odg index 303daa0..30d01fc 100644 Binary files a/design_files/design.odg and b/design_files/design.odg differ diff --git a/design_files/design_7inchvinyl.odg b/design_files/design_7inchvinyl.odg new file mode 100644 index 0000000..20a41e3 Binary files /dev/null and b/design_files/design_7inchvinyl.odg differ diff --git a/fritzing_files/64 analog input.fzz b/fritzing_files/64 analog input.fzz deleted file mode 100644 index c80701b..0000000 Binary files a/fritzing_files/64 analog input.fzz and /dev/null differ diff --git a/fritzing_files/INPUT_PLATINE.fzz b/fritzing_files/INPUT_PLATINE.fzz new file mode 100644 index 0000000..8cbff9b Binary files /dev/null and b/fritzing_files/INPUT_PLATINE.fzz differ diff --git a/fritzing_files/bombatuino.fzz b/fritzing_files/bombatuino.fzz deleted file mode 100644 index 6578614..0000000 Binary files a/fritzing_files/bombatuino.fzz and /dev/null differ diff --git a/fritzing_files/input_Platte.fzz b/fritzing_files/input_Platte.fzz deleted file mode 100644 index d53fea5..0000000 Binary files a/fritzing_files/input_Platte.fzz and /dev/null differ diff --git a/source/INPUT_MCP23017_test/INPUT_MCP23017_test.ino b/source/INPUT_MCP23017_test/INPUT_MCP23017_test.ino index 7bf3701..992058c 100644 --- a/source/INPUT_MCP23017_test/INPUT_MCP23017_test.ino +++ b/source/INPUT_MCP23017_test/INPUT_MCP23017_test.ino @@ -1,15 +1,20 @@ #include -#include -#include +#include +#include +#include +#include INPUT_MCP23017 input_MCP23017; INPUT_74HC4051 input_4051; +ROTARY_ENCODER rot(incement,decrement); +MIDI Midi; void setup() { - Serial.begin(9600); - input_MCP23017.begin(0,printValue); - input_4051.begin(A0,11,12,13,printValue); + //Serial.begin(9600); + Midi.begin(); + input_MCP23017.begin(0,sendNote); + input_4051.begin(A0,11,12,13,sendCC); } void loop() { @@ -17,12 +22,32 @@ void loop() { input_4051.loop(); } -void printValue(int id, int pin, int value) { - Serial.print("id: "); - Serial.print(id); - Serial.print(" pin: "); - Serial.print(pin); - Serial.print(" value: "); - Serial.print(value); - Serial.println(); +void sendNote(int id, int pin, int value) { + if (pin == 15) { + rot.setPinB(value); + } else + if (pin == 14) { + rot.setPinA(value); + } else { + if (value == HIGH) { + Midi.noteOn(id*16+pin,MIDI_MAX_DATA); + } + else { + //Midi.noteOff(id*16+pin); + } + } +} + +void sendCC(int id, int pin, int value) { + Midi.controlChange(id*8+pin,value/8); +} + +void incement() { + Midi.noteOn(16+14,MIDI_MAX_DATA); + //Midi.noteOff(16+14); +} + +void decrement() { + Midi.noteOn(16+15,MIDI_MAX_DATA); + //Midi.noteOff(16+15); } diff --git a/source/MIDI_library_test/MIDI_library_test.ino b/source/MIDI_library_test/MIDI_library_test.ino new file mode 100644 index 0000000..7e6ae8f --- /dev/null +++ b/source/MIDI_library_test/MIDI_library_test.ino @@ -0,0 +1,12 @@ + +#include + +MIDI Midi; + +void setup() { + Midi.begin(); +} + +void loop() { + Midi.noteOn(0x3C,0x64); +} diff --git a/source/libraries/INPUT_74HC4051/INPUT_74HC4051.cpp b/source/libraries/bombatuino_INPUT_74HC4051/bombatuino_INPUT_74HC4051.cpp similarity index 97% rename from source/libraries/INPUT_74HC4051/INPUT_74HC4051.cpp rename to source/libraries/bombatuino_INPUT_74HC4051/bombatuino_INPUT_74HC4051.cpp index edb090b..91ddeab 100644 --- a/source/libraries/INPUT_74HC4051/INPUT_74HC4051.cpp +++ b/source/libraries/bombatuino_INPUT_74HC4051/bombatuino_INPUT_74HC4051.cpp @@ -1,5 +1,5 @@ #include "Arduino.h" -#include "INPUT_74HC4051.h" +#include "bombatuino_INPUT_74HC4051.h" //should be called in setup() void INPUT_74HC4051::begin(uint8_t analog, uint8_t s0, uint8_t s1, uint8_t s2,CallbackFunction cbF) { diff --git a/source/libraries/INPUT_74HC4051/INPUT_74HC4051.h b/source/libraries/bombatuino_INPUT_74HC4051/bombatuino_INPUT_74HC4051.h similarity index 93% rename from source/libraries/INPUT_74HC4051/INPUT_74HC4051.h rename to source/libraries/bombatuino_INPUT_74HC4051/bombatuino_INPUT_74HC4051.h index 9bc8caf..14ed372 100644 --- a/source/libraries/INPUT_74HC4051/INPUT_74HC4051.h +++ b/source/libraries/bombatuino_INPUT_74HC4051/bombatuino_INPUT_74HC4051.h @@ -1,5 +1,5 @@ /** - * @file INPUT_74HC4051.h + * @file bombatuino_INPUT_74HC4051.h * * @author Lukas Haubaum (lukas@haubaum.de) * @@ -10,9 +10,8 @@ * library is for specialiced use: all I/O ports are used as analog inputs, values are stored and a callback function is called, when a value changes * * */ -#ifndef INPUT_74HC4051_h -#define INPUT_74HC4051_h - +#ifndef bombatuino_INPUT_74HC4051_h +#define bombatuino_INPUT_74HC4051_h #define INPUT_74HC4051_TOLERANCE 1 /**< I/O DIRECTION REGISTER PORT A - Controls the direction of the data I/O. */ diff --git a/source/libraries/INPUT_MCP23017/INPUT_MCP23017.cpp b/source/libraries/bombatuino_INPUT_MCP23017/bombatuino_INPUT_MCP23017.cpp similarity index 83% rename from source/libraries/INPUT_MCP23017/INPUT_MCP23017.cpp rename to source/libraries/bombatuino_INPUT_MCP23017/bombatuino_INPUT_MCP23017.cpp index 46508ef..a4aa824 100644 --- a/source/libraries/INPUT_MCP23017/INPUT_MCP23017.cpp +++ b/source/libraries/bombatuino_INPUT_MCP23017/bombatuino_INPUT_MCP23017.cpp @@ -1,7 +1,7 @@ #include #include "Arduino.h" -#include "INPUT_MCP23017.h" +#include "bombatuino_INPUT_MCP23017.h" void INPUT_MCP23017::begin(uint8_t addr,CallbackFunction cbF) { Wire.begin(); @@ -15,34 +15,34 @@ void INPUT_MCP23017::begin(uint8_t addr,CallbackFunction cbF) { //set all ports as inputs Wire.beginTransmission(MCP23017_ADDRESS | _addr); - Wire.write((byte)MCP23017_IODIRA); //PORT A + Wire.write((byte)MCP23017_IODIR_A); //PORT A Wire.write(0xFF); Wire.endTransmission(); Wire.beginTransmission(MCP23017_ADDRESS | _addr); - Wire.write(MCP23017_IODIRB); //PORT B + Wire.write(MCP23017_IODIR_B); //PORT B Wire.write(0xFF); Wire.endTransmission(); //activate pullup resistors Wire.beginTransmission(MCP23017_ADDRESS | _addr); - Wire.write(MCP23017_GPPUA); //PORT A + Wire.write(MCP23017_GPPU_A); //PORT A Wire.write(0xFF); Wire.endTransmission(); Wire.beginTransmission(MCP23017_ADDRESS | _addr); - Wire.write(MCP23017_GPPUB); //PORT B + Wire.write(MCP23017_GPPU_B); //PORT B Wire.write(0xFF); Wire.endTransmission(); //inverse all inputs Wire.beginTransmission(MCP23017_ADDRESS | _addr); - Wire.write((byte)MCP23017_IPOLA); //PORT A + Wire.write((byte)MCP23017_IPOL_A); //PORT A Wire.write(0xFF); Wire.endTransmission(); Wire.beginTransmission(MCP23017_ADDRESS | _addr); - Wire.write(MCP23017_IPOLB); //PORT B + Wire.write(MCP23017_IPOL_B); //PORT B Wire.write(0xFF); Wire.endTransmission(); @@ -50,7 +50,7 @@ void INPUT_MCP23017::begin(uint8_t addr,CallbackFunction cbF) { uint8_t pin,bank; //read bank A Wire.beginTransmission(MCP23017_ADDRESS | _addr); - Wire.write(MCP23017_GPIOA); + Wire.write(MCP23017_GPIO_A); Wire.endTransmission(); Wire.requestFrom(MCP23017_ADDRESS | _addr, 1); bank = Wire.read(); @@ -58,7 +58,7 @@ void INPUT_MCP23017::begin(uint8_t addr,CallbackFunction cbF) { _value[pin] = (bank >> pin) & 0x1; //read bank B Wire.beginTransmission(MCP23017_ADDRESS | _addr); - Wire.write(MCP23017_GPIOB); + Wire.write(MCP23017_GPIO_B); Wire.endTransmission(); Wire.requestFrom(MCP23017_ADDRESS | _addr, 1); bank = Wire.read(); @@ -71,7 +71,7 @@ void INPUT_MCP23017::loop() { int value; //read bank A Wire.beginTransmission(MCP23017_ADDRESS | _addr); - Wire.write(MCP23017_GPIOA); + Wire.write(MCP23017_GPIO_A); Wire.endTransmission(); Wire.requestFrom(MCP23017_ADDRESS | _addr, 1); bank = Wire.read(); @@ -84,7 +84,7 @@ void INPUT_MCP23017::loop() { } //read bank B Wire.beginTransmission(MCP23017_ADDRESS | _addr); - Wire.write(MCP23017_GPIOB); + Wire.write(MCP23017_GPIO_B); Wire.endTransmission(); Wire.requestFrom(MCP23017_ADDRESS | _addr, 1); bank = Wire.read(); @@ -104,10 +104,10 @@ int INPUT_MCP23017::getSpecificValue(uint8_t pin) { Wire.beginTransmission(MCP23017_ADDRESS | _addr); uint8_t p = pin; if (pin > 8) { - Wire.write(MCP23017_GPIOB); + Wire.write(MCP23017_GPIO_B); p -= 8; } else - Wire.write(MCP23017_GPIOA); + Wire.write(MCP23017_GPIO_A); Wire.endTransmission(); uint8_t bank = Wire.read(); int value = (bank >> p) & 0x1; diff --git a/source/libraries/INPUT_MCP23017/INPUT_MCP23017.h b/source/libraries/bombatuino_INPUT_MCP23017/bombatuino_INPUT_MCP23017.h similarity index 95% rename from source/libraries/INPUT_MCP23017/INPUT_MCP23017.h rename to source/libraries/bombatuino_INPUT_MCP23017/bombatuino_INPUT_MCP23017.h index 7019d98..794f749 100644 --- a/source/libraries/INPUT_MCP23017/INPUT_MCP23017.h +++ b/source/libraries/bombatuino_INPUT_MCP23017/bombatuino_INPUT_MCP23017.h @@ -1,5 +1,5 @@ /** - * @file INPUT_MCP23017.h + * @file bombatuino_INPUT_MCP23017.h * * @author Lukas Haubaum (lukas@haubaum.de) * @@ -7,11 +7,12 @@ * * @brief arduino library for reading inputs from MCP23017 port Expander * - * library is for specialiced use: all I/O ports are used as digital inputs with internal pullup resistor active, values are stored and a callback function is called, when a value changes + * library is for specialiced use: all I/O ports are used as digital inputs with internal pullup resistor active, values are stored and a callback function is called, when a value changes. + * ATTETION: Wire.h must be included in sketch #include * * */ -#ifndef INPUT_MCP23017_h -#define INPUT_MCP23017_h +#ifndef bombatuino_INPUT_MCP23017_h +#define bombatuino_INPUT_MCP23017_h #if !defined(CallbackFunction) /** diff --git a/source/libraries/bombatuino_MIDI/bombatuino_MIDI.cpp b/source/libraries/bombatuino_MIDI/bombatuino_MIDI.cpp new file mode 100644 index 0000000..f943cf8 --- /dev/null +++ b/source/libraries/bombatuino_MIDI/bombatuino_MIDI.cpp @@ -0,0 +1,59 @@ +#include "Arduino.h" +#include "bombatuino_MIDI.h" + +void MIDI::begin(int channel) { + Serial.begin(31250); + //if given channel is not valid, set default channel to 1 + if (channel > MIDI_MAX_CHANNEL) + channel = MIDI_DEFAULT_CHANNEL; + _channel = channel; +} + +bool MIDI::message(int status, int data, int data2, int channel) { + //check if status byte is valid + if (status > MIDI_MAX_STATUS) return false; + //check if first data byte is valid + if (data > MIDI_MAX_DATA) return false; + //check if second data byte is valid + if (data2 > MIDI_MAX_DATA) return false; + //if no specific channel given, use default channel + if (channel == MIDI_NULL_CHANNEL) channel = _channel; + //check if channel is valid + if (channel > MIDI_MAX_CHANNEL) return false; + //write bytes to serial + Serial.write(status+channel); + Serial.write(data); + //check if second data byte should be send + if (status != MIDI_PROGRAMM_CHANGE && status != MIDI_CHANNEL_PRESSURE) + Serial.write(data2); + return true; +} + +bool MIDI::noteOff(int note, int velocity, int channel) { + return message(MIDI_NOTE_OFF,note,velocity,channel); +} + +bool MIDI::noteOn(int note, int velocity, int channel) { + return message(MIDI_NOTE_ON,note,velocity,channel); +} + +bool MIDI::polyphonicKeyPressure(int note, int velocity, int channel) { + return message(MIDI_POLYPHONIC_KEY_PRESSURE,note,velocity,channel); +} + +bool MIDI::controlChange(int controller, int value, int channel) { + return message(MIDI_CONTROL_CHANGE,controller,value,channel); +} + +bool MIDI::programChange(int programm, int channel) { + return message(MIDI_PROGRAMM_CHANGE,programm,0,channel); +} + +bool MIDI::channelPressure(int pressure, int channel) { + return message(MIDI_CHANNEL_PRESSURE,pressure,0,channel); +} + +bool MIDI::pitchWheelChange(int last, int most, int channel) { + return message(MIDI_PITCH_WHEEL_CHANGE,last,most,channel); +} + diff --git a/source/libraries/bombatuino_MIDI/bombatuino_MIDI.h b/source/libraries/bombatuino_MIDI/bombatuino_MIDI.h new file mode 100644 index 0000000..a3a37da --- /dev/null +++ b/source/libraries/bombatuino_MIDI/bombatuino_MIDI.h @@ -0,0 +1,123 @@ +/** + * @file bombatuino_MIDI.h + * + * @author Lukas Haubaum (lukas@haubaum.de) + * + * @date February, 2013 + * + * @brief arduino library for sending MIDI messages over serial + * + * library is just for sending MIDI messages over normal Serial (TX), not for receiving. + * + * */ + +#ifndef bombatuino_MIDI_h +#define bombatuino_MIDI_h + +#define MIDI_NOTE_OFF 0x80 +#define MIDI_NOTE_ON 0x90 +#define MIDI_POLYPHONIC_KEY_PRESSURE 0xA0 +#define MIDI_CONTROL_CHANGE 0xB0 +#define MIDI_PROGRAMM_CHANGE 0xC0 +#define MIDI_CHANNEL_PRESSURE 0xD0 +#define MIDI_PITCH_WHEEL_CHANGE 0xE0 + +#define MIDI_DEFAULT_CHANNEL 0x00 +#define MIDI_MAX_STATUS 0xE0 +#define MIDI_MAX_CHANNEL 0x0F +#define MIDI_MAX_DATA 0x7F +#define MIDI_NULL_CHANNEL -1 + +class MIDI { + public: + /** + * initalize the class, should be called in setup() function + * + * !IMPORTANT sets Serial baud rate to the default MIDI baud rate, so do not change baud rate manually + * + * @param optional: default MIDI channel + */ + void begin(int channel = MIDI_DEFAULT_CHANNEL); + /** + * send MIDI message over Serial + * + * @param status byte + * @param first data byte + * @param second data byte + * @param optional: MIDI channel + * + * @return false, if an error occurs + */ + bool message(int status, int data, int data2, int channel = MIDI_NULL_CHANNEL); + /** + * send Note off MIDI message + * + * @param note number + * @param optional: velocity + * @param optional: MIDI channel + * + * @return false, if an error occurs + */ + bool noteOff(int note, int velocity = MIDI_MAX_DATA, int channel = MIDI_NULL_CHANNEL); + /** + * send Note on MIDI message + * + * @param note number + * @param velocity + * @param optional: MIDI channel + * + * @return false, if an error occurs + */ + bool noteOn(int note, int velocity, int channel = MIDI_NULL_CHANNEL); + /** + * send polyphinic key pressure MIDI message + * + * @param note number + * @param velocity + * @param optional: MIDI channel + * + * @return false, if an error occurs + */ + bool polyphonicKeyPressure(int note, int velocity, int channel = MIDI_NULL_CHANNEL); + /** + * send control change MIDI message + * + * @param controller number + * @param value + * @param optional: MIDI channel + */ + bool controlChange(int controller, int value, int channel = MIDI_NULL_CHANNEL); + /** + * send program change MIDI message + * + * @param programm number + * @param optional: MIDI channel + * + * @return false, if an error occurs + */ + bool programChange(int programm, int channel = MIDI_NULL_CHANNEL); + /** + * send channel pressure MIDI message + * + * @param pressure value + * @param optional: MIDI channel + * + * @return false, if an error occurs + */ + bool channelPressure(int pressure, int channel = MIDI_NULL_CHANNEL); + /** + * send pitch wheel change MIDI message + * + * @param last significant bits + * @param most significant bits + * @param optional: MIDI channel + * + * @return false, if an error occurs + */ + bool pitchWheelChange(int last, int most, int channel = MIDI_NULL_CHANNEL); + private: + int _channel; /**> the default MIDI channel */ +}; + + +#endif diff --git a/source/libraries/bombatuino_ROTARY_ENCODER/bombatuino_ROTARY_ENCODER.cpp b/source/libraries/bombatuino_ROTARY_ENCODER/bombatuino_ROTARY_ENCODER.cpp new file mode 100644 index 0000000..3fe4237 --- /dev/null +++ b/source/libraries/bombatuino_ROTARY_ENCODER/bombatuino_ROTARY_ENCODER.cpp @@ -0,0 +1,33 @@ + +#include "Arduino.h" +#include "bombatuino_ROTARY_ENCODER.h" + +ROTARY_ENCODER::ROTARY_ENCODER(XcrementFunction incrementFunction, XcrementFunction decrementFunction) { + _increment = incrementFunction; + _decrement = decrementFunction; + _pinA = LOW; + _pinB = LOW; + _oldA = LOW; +} + +void ROTARY_ENCODER::setPinB(int value) { + _pinB = value; + onPinChange(); +} + +void ROTARY_ENCODER::setPinA(int value) { + _pinA = value; + onPinChange(); +} + +void ROTARY_ENCODER::onPinChange() { + if ((_oldA == LOW) && (_pinA == HIGH)) { + if (_pinB == LOW) { + (*_increment)(); + } + else { + (*_decrement)(); + } + } + _oldA = _pinA; +} diff --git a/source/libraries/bombatuino_ROTARY_ENCODER/bombatuino_ROTARY_ENCODER.h b/source/libraries/bombatuino_ROTARY_ENCODER/bombatuino_ROTARY_ENCODER.h new file mode 100644 index 0000000..5026e0e --- /dev/null +++ b/source/libraries/bombatuino_ROTARY_ENCODER/bombatuino_ROTARY_ENCODER.h @@ -0,0 +1,58 @@ +/** + * @file bombatuino_ROTARY_ENCODER.h + * + * @author Lukas Haubaum (lukas@haubaum.de) + * + * @date February, 2013 + * + * @brief arduino library for handling a rotary encoder + * + * library is for specialiced use: increment- and decrement-functions are called on change of pin A. + * + * */ +#ifndef bombatuino_ROTARY_ENCODER_h +#define bombatuino_ROTARY_ENCODER_h + +#if !defined(XcrementFunction) +/** + * callback function + * + * @param address + * @param pin + * @param value + */ +typedef void (*XcrementFunction)(void); +#endif + +class ROTARY_ENCODER +{ + public: + /** + * constructor + * + * @param increment function + * @param decrement function + */ + ROTARY_ENCODER(XcrementFunction incrementFunction, XcrementFunction decrementFunction); + /** + * set the value of pin B + * + * @param value of B-pin + */ + void setPinB(int value); + /** + * set the value of pin A + * + * @param value of A-pin + */ + void setPinA(int value); + private: + int _pinA; + int _pinB; + int _oldA; + XcrementFunction _increment; /**< increment function */ + XcrementFunction _decrement; /**< decrement function */ + void onPinChange(); +}; + +#endif