This commit is contained in:
Lukas 2013-05-14 08:28:05 +02:00
parent 0eec581c8a
commit e12d12238b
8 changed files with 137 additions and 137 deletions

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,20 @@
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
}
void loop(){
int buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}

View File

@ -3,18 +3,14 @@
#include <bombatuino_INPUT_MCP23017.h> #include <bombatuino_INPUT_MCP23017.h>
#include <bombatuino_INPUT_74HC4051.h> #include <bombatuino_INPUT_74HC4051.h>
#include <bombatuino_ROTARY_ENCODER.h> #include <bombatuino_ROTARY_ENCODER.h>
#include <bombatuino_MIDI.h>
INPUT_MCP23017 input_MCP23017; INPUT_MCP23017 input_MCP23017;
INPUT_74HC4051 input_4051; INPUT_74HC4051 input_4051;
ROTARY_ENCODER rot(incement,decrement);
MIDI Midi;
void setup() { void setup() {
//Serial.begin(9600); Serial.begin(9600);
Midi.begin(); input_MCP23017.begin(0,printData);
input_MCP23017.begin(0,sendNote); input_4051.begin(A3,10,11,12,printData);
input_4051.begin(A0,11,12,13,sendCC);
} }
void loop() { void loop() {
@ -22,32 +18,13 @@ void loop() {
input_4051.loop(); input_4051.loop();
} }
void sendNote(int id, int pin, int value) { void printData(int id, int pin, int value) {
if (pin == 15) { Serial.print("id");
rot.setPinB(value); Serial.print(id);
} else Serial.print(" - ");
if (pin == 14) { Serial.print("pin");
rot.setPinA(value); Serial.print(pin);
} else { Serial.print(" : ");
if (value == HIGH) { Serial.print(value);
Midi.noteOn(id*16+pin,MIDI_MAX_DATA); Serial.println();
}
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);
} }

View File

@ -1,99 +0,0 @@
#include <Wire.h>
#define MCP23017_ADDRESS 0x20
// registers (from https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library/blob/master/Adafruit_MCP23017.h)
#define MCP23017_IODIRA 0x00
#define MCP23017_IPOLA 0x02
#define MCP23017_GPINTENA 0x04
#define MCP23017_DEFVALA 0x06
#define MCP23017_INTCONA 0x08
#define MCP23017_IOCONA 0x0A
#define MCP23017_GPPUA 0x0C
#define MCP23017_INTFA 0x0E
#define MCP23017_INTCAPA 0x10
#define MCP23017_GPIOA 0x12
#define MCP23017_OLATA 0x14
#define MCP23017_IODIRB 0x01
#define MCP23017_IPOLB 0x03
#define MCP23017_GPINTENB 0x05
#define MCP23017_DEFVALB 0x07
#define MCP23017_INTCONB 0x09
#define MCP23017_IOCONB 0x0B
#define MCP23017_GPPUB 0x0D
#define MCP23017_INTFB 0x0F
#define MCP23017_INTCAPB 0x11
#define MCP23017_GPIOB 0x13
#define MCP23017_OLATB 0x15
int _addr = 0;
int _value[16];
void setup() {
Serial.begin(9600);
Wire.begin();
// set defaults!
Wire.beginTransmission(MCP23017_ADDRESS | _addr);
Wire.write((byte)MCP23017_IODIRA);
Wire.write(0xFF); // all inputs on port A
Wire.endTransmission();
Wire.beginTransmission(MCP23017_ADDRESS | _addr);
Wire.write(MCP23017_IODIRB);
Wire.write(0xFF); // all inputs on port B
Wire.endTransmission();
Wire.beginTransmission(MCP23017_ADDRESS | _addr);
Wire.write(MCP23017_GPPUA);
Wire.write(0xFF); // all pullup resistors on port A
Wire.endTransmission();
Wire.beginTransmission(MCP23017_ADDRESS | _addr);
Wire.write(MCP23017_GPPUB);
Wire.write(0xFF); // all pullup resistors on port B
Wire.endTransmission();
}
void loop() {
uint8_t pin,bank;
int value;
//read bank A
Wire.beginTransmission(MCP23017_ADDRESS | _addr);
Wire.write(MCP23017_GPIOA);
Wire.endTransmission();
Wire.requestFrom(MCP23017_ADDRESS | _addr, 1);
bank = Wire.read();
for (pin=0; pin<8; pin++) {
value = (bank >> pin) & 0x1;
if (_value[pin] != value) {
_value[pin] = value;
printValue(_addr,pin,value);
}
}
//read bank B
Wire.beginTransmission(MCP23017_ADDRESS | _addr);
Wire.write(MCP23017_GPIOB);
Wire.endTransmission();
Wire.requestFrom(MCP23017_ADDRESS | _addr, 1);
bank = Wire.read();
for (pin=8; pin<16; pin++) {
value = (bank >> (pin-8)) & 0x1;
if (_value[pin] != value) {
_value[pin] = value;
printValue(_addr,pin,value);
}
}
}
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();
}

View File

@ -0,0 +1,102 @@
#include <Wire.h>
#include <bombatuino_INPUT_MCP23017.h>
#include <bombatuino_INPUT_74HC4051.h>
#include <bombatuino_ROTARY_ENCODER.h>
#include <bombatuino_MIDI.h>
MIDI Midi;
INPUT_MCP23017 input_MCP23017_0;
INPUT_MCP23017 input_MCP23017_1;
INPUT_MCP23017 input_MCP23017_3;
INPUT_MCP23017 input_MCP23017_4;
ROTARY_ENCODER re_JogWheel1(rotaryLeftJogWheel1,rotaryRightJogWheel1);
ROTARY_ENCODER re_JogWheel2(rotaryLeftJogWheel2,rotaryRightJogWheel2);
ROTARY_ENCODER re_Browse(rotaryLeftBrowse,rotaryRightBrowse);
INPUT_74HC4051 input_4051_A0;
INPUT_74HC4051 input_4051_A1;
INPUT_74HC4051 input_4051_A2;
void setup() {
Midi.begin();
input_MCP23017_0.begin(0,printDigitalData);
input_MCP23017_1.begin(1,printDigitalData);
input_MCP23017_3.begin(3,printDigitalData);
input_MCP23017_4.begin(4,printDigitalData);
input_4051_A0.begin(A0,8,9,10,printAnalogData);
input_4051_A1.begin(A1,8,9,10,printAnalogData);
input_4051_A2.begin(A2,8,9,10,printAnalogData);
}
void loop() {
input_MCP23017_0.loop();
input_MCP23017_1.loop();
input_MCP23017_3.loop();
input_MCP23017_4.loop();
input_4051_A0.loop();
input_4051_A1.loop();
input_4051_A2.loop();
}
void printAnalogData(int id, int pin, int value) {
Midi.controlChange((id-A0) * 8 + pin,value);
}
void printDigitalData(int id, int pin, int value) {
if (id == 1 && pin == 6)
re_JogWheel1.setPinA(value);
if (id == 1 && pin == 7)
re_JogWheel1.setPinB(value);
if (id == 3 && pin == 9)
re_JogWheel2.setPinA(value);
if (id == 3 && pin == 10)
re_JogWheel2.setPinB(value);
if (id == 3 && pin == 6)
re_Browse.setPinA(value);
if (id == 3 && pin == 5)
re_Browse.setPinB(value);
if ((id == 3 && pin != 5 && pin != 6 && pin!= 9 && pin != 10) || (id == 1 && pin != 6 && pin !=7) || (id == 0) || (id == 4)) {
if (value == HIGH)
Midi.noteOn(id * 16 + pin, MIDI_MAX_DATA);
else Midi.noteOff(id * 16 + pin);
}
}
//JogWheel1
void rotaryLeftJogWheel1() {
Midi.noteOn(1 * 16 + 6, MIDI_MAX_DATA);
Midi.noteOff(1 * 16 + 6);
}
void rotaryRightJogWheel1() {
Midi.noteOn(1 * 16 + 7, MIDI_MAX_DATA);
Midi.noteOff(1 * 16 + 7);
}
//JogWheel2
void rotaryLeftJogWheel2() {
Midi.noteOn(3 * 16 + 9, MIDI_MAX_DATA);
Midi.noteOff(3 * 16 + 9);
}
void rotaryRightJogWheel2() {
Midi.noteOn(3 * 16 + 10, MIDI_MAX_DATA);
Midi.noteOff(3 * 16 + 10);
}
//Browse
void rotaryLeftBrowse() {
Midi.noteOn(3 * 16 + 6, MIDI_MAX_DATA);
Midi.noteOff(3 * 16 + 6);
}
void rotaryRightBrowse() {
Midi.noteOn(3 * 16 + 5, MIDI_MAX_DATA);
Midi.noteOff(3 * 16 + 5);
}

View File

@ -49,7 +49,7 @@ void INPUT_74HC4051::loop() {
digitalWrite(_s2, r2); digitalWrite(_s2, r2);
//not sure if nessesary //not sure if nessesary
//delayMicroseconds(10); //delayMicroseconds(10);
value = analogRead(_analog); value = analogRead(_analog) / 8;
if (_value[pin] < value - INPUT_74HC4051_TOLERANCE || _value[pin] > value + INPUT_74HC4051_TOLERANCE) { if (_value[pin] < value - INPUT_74HC4051_TOLERANCE || _value[pin] > value + INPUT_74HC4051_TOLERANCE) {
_value[pin] = value; _value[pin] = value;
(*_callbackFunction)(_analog,pin,value); (*_callbackFunction)(_analog,pin,value);
@ -69,7 +69,7 @@ int INPUT_74HC4051::getSpecificValue(uint8_t pin) {
digitalWrite(_s1, r1); digitalWrite(_s1, r1);
digitalWrite(_s2, r2); digitalWrite(_s2, r2);
//delayMicroseconds(10); //delayMicroseconds(10);
int value = analogRead(_analog); int value = analogRead(_analog) / 8;
_value[pin] = value; _value[pin] = value;
return value; return value;
} }

View File

@ -13,7 +13,7 @@
#ifndef bombatuino_INPUT_74HC4051_h #ifndef bombatuino_INPUT_74HC4051_h
#define 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. */ #define INPUT_74HC4051_TOLERANCE 0 /**< I/O DIRECTION REGISTER PORT A - Controls the direction of the data I/O. */
#if !defined(CallbackFunction) #if !defined(CallbackFunction)
/** /**