updated libaries, debug mode for MIDI libary, commented bambatu.ino sketch

This commit is contained in:
Lukas
2013-05-18 10:28:50 +02:00
parent 89c20bb101
commit d053ca9637
7 changed files with 115 additions and 64 deletions
@@ -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.
*