I am doing a DIY midi controller project using 9 potentiometers and 16 arcade buttons. I have edited an existing script written for a controller with less buttons made for the Teensy 2.0
The circuit uses analog inputs A0-A9
And digital inputs 0-12 & 24-27
Will this code work on the teensy 3.2 ? Or is there anything else i need to change ?
#include <Bounce.h>
// define how many pots are active up to number of available analog inputs
#define analogInputs 9
// make arrays for input values and lagged input values
int inputAnalog[analogInputs];
int iAlag[analogInputs];
// make array of cc values
int ccValue[analogInputs];
// index variable for loop
int i;
// cc values for buttons
int cc_off = 0;
int cc_on = 65;
int cc_super = 127;
// map buttons to cc for button
int cc0 = 45;
int cc1 = 46;
int cc2 = 47;
int cc3 = 48;
int cc4 = 49;
int cc5 = 50;
int cc6 = 51;
int cc7 = 52;
int cc8 = 53;
int cc9 = 54;
int cc10 = 55;
int cc11 = 56;
int cc12 = 57;
int cc13 = 58;
int cc14 = 59;
int cc15 = 60;
Bounce
Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5);
Bounce button2 = Bounce(2, 5);
Bounce button3 = Bounce(3, 5);
Bounce button4 = Bounce(4, 5);
Bounce button5 = Bounce(5, 5);
Bounce button6 = Bounce(6, 5);
Bounce button7 = Bounce(7, 5);
Bounce button8 = Bounce(8, 5);
Bounce button9 = Bounce(9, 5);
Bounce button10 = Bounce(10, 5);
Bounce button11 = Bounce(11, 5);
Bounce button12 = Bounce(12, 5);
Bounce button13 = Bounce(13, 5);
Bounce button14 = Bounce(14, 5);
Bounce button15 = Bounce(15, 5);
void setup() {
// MIDI rate
Serial.begin(31250);
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(15, INPUT_PULLUP);
pinMode(16, INPUT_PULLUP);
pinMode(17, INPUT_PULLUP);
pinMode(18, INPUT_PULLUP);
pinMode(19, INPUT_PULLUP);
pinMode(20, INPUT_PULLUP);
pinMode(21, INPUT_PULLUP);
pinMode(22, INPUT_PULLUP);
pinMode(23, INPUT_PULLUP);
pinMode(24, INPUT_PULLUP);
pinMode(25, INPUT_PULLUP);
pinMode(26, INPUT_PULLUP);
pinMode(27, INPUT_PULLUP);
}
void loop() {
// loop trough active inputs for knobs
for (i=0;i<analogInputs;i++){
// read current value at i-th input
inputAnalog = analogRead(i);
// if magnitude of difference is 8 or more...
if (abs(inputAnalog - iAlag) > 7){
// calc the CC value based on the raw value
ccValue = inputAnalog/8;
// send the MIDI
usbMIDI.sendControlChange(i, ccValue, 3);
// set raw reading to lagged array for next comparison
iAlag = inputAnalog;
}
delay(5); // limits MIDI messages to reasonable number
}
// Push Button code
button0.update();
button1.update();
button2.update();
button3.update();
button4.update();
button5.update();
button6.update();
button7.update();
button8.update();
button9.update();
button10.update();
button11.update();
button12.update();
button13.update();
button14.update();
button15.update();
if (button0.fallingEdge())
{
usbMIDI.sendControlChange(cc0, cc_on, 3);
}
if (button1.fallingEdge())
{
usbMIDI.sendControlChange(cc1, cc_on, 3);
}
if (button2.fallingEdge())
{
usbMIDI.sendControlChange(cc2, cc_on, 3);
}
if (button3.fallingEdge())
{
usbMIDI.sendControlChange(cc3, cc_on, 3);
}
if (button4.fallingEdge())
{
usbMIDI.sendControlChange(cc4, cc_on, 3);
{
if (button5.fallingEdge())
{
usbMIDI.sendControlChange(cc5, cc_on, 3);
{
if (button6.fallingEdge())
{
usbMIDI.sendControlChange(cc6, cc_on, 3);
{
if (button7.fallingEdge())
{
usbMIDI.sendControlChange(cc7, cc_on, 3);
{
if (button8.fallingEdge())
{
usbMIDI.sendControlChange(cc8, cc_on, 3);
{
if (button9.fallingEdge())
{
usbMIDI.sendControlChange(cc9, cc_on, 3);
{
if (button10.fallingEdge())
{
usbMIDI.sendControlChange(cc10, cc_on, 3);
{
if (button11.fallingEdge())
{
usbMIDI.sendControlChange(cc11, cc_on, 3);
{
if (button12.fallingEdge())
{
usbMIDI.sendControlChange(cc12, cc_on, 3);
{
if (button13.fallingEdge())
{
usbMIDI.sendControlChange(cc13, cc_on, 3);
{
if (button14.fallingEdge())
{
usbMIDI.sendControlChange(cc14, cc_on, 3);
{
if (button15.fallingEdge())
{
usbMIDI.sendControlChange(cc15, cc_on, 3);
{
if (button0.risingEdge())
{
usbMIDI.sendControlChange(cc0, cc_off, 3);
}
if (button1.risingEdge())
{
usbMIDI.sendControlChange(cc1, cc_off, 3);
}
if (button2.risingEdge())
{
usbMIDI.sendControlChange(cc2, cc_off, 3);
}
if (button3.risingEdge())
{
usbMIDI.sendControlChange(cc3, cc_off, 3);
}
if (button4.risingEdge())
{
usbMIDI.sendControlChange(cc4, cc_off, 3);
}
if (button5.risingEdge())
{
usbMIDI.sendControlChange(cc5, cc_off, 3);
}
if (button6.risingEdge())
{
usbMIDI.sendControlChange(cc6, cc_off, 3);
}
if (button7.risingEdge())
{
usbMIDI.sendControlChange(cc7, cc_off, 3);
}
if (button8.risingEdge())
{
usbMIDI.sendControlChange(cc8, cc_off, 3);
}
if (button9.risingEdge())
{
usbMIDI.sendControlChange(cc9, cc_off, 3);
}
if (button10.risingEdge())
{
usbMIDI.sendControlChange(cc10, cc_off, 3);
}
if (button11.risingEdge())
{
usbMIDI.sendControlChange(cc11, cc_off, 3);
}
if (button12.risingEdge())
{
usbMIDI.sendControlChange(cc12, cc_off, 3);
}
if (button13.risingEdge())
{
usbMIDI.sendControlChange(cc13, cc_off, 3);
}
if (button14.risingEdge())
{
usbMIDI.sendControlChange(cc14, cc_off, 3);
}
if (button15.risingEdge())
{
usbMIDI.sendControlChange(cc15, cc_off, 3);
}
}
Any help is greatly appreciated.
thanks
James
The circuit uses analog inputs A0-A9
And digital inputs 0-12 & 24-27
Will this code work on the teensy 3.2 ? Or is there anything else i need to change ?
#include <Bounce.h>
// define how many pots are active up to number of available analog inputs
#define analogInputs 9
// make arrays for input values and lagged input values
int inputAnalog[analogInputs];
int iAlag[analogInputs];
// make array of cc values
int ccValue[analogInputs];
// index variable for loop
int i;
// cc values for buttons
int cc_off = 0;
int cc_on = 65;
int cc_super = 127;
// map buttons to cc for button
int cc0 = 45;
int cc1 = 46;
int cc2 = 47;
int cc3 = 48;
int cc4 = 49;
int cc5 = 50;
int cc6 = 51;
int cc7 = 52;
int cc8 = 53;
int cc9 = 54;
int cc10 = 55;
int cc11 = 56;
int cc12 = 57;
int cc13 = 58;
int cc14 = 59;
int cc15 = 60;
Bounce
Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5);
Bounce button2 = Bounce(2, 5);
Bounce button3 = Bounce(3, 5);
Bounce button4 = Bounce(4, 5);
Bounce button5 = Bounce(5, 5);
Bounce button6 = Bounce(6, 5);
Bounce button7 = Bounce(7, 5);
Bounce button8 = Bounce(8, 5);
Bounce button9 = Bounce(9, 5);
Bounce button10 = Bounce(10, 5);
Bounce button11 = Bounce(11, 5);
Bounce button12 = Bounce(12, 5);
Bounce button13 = Bounce(13, 5);
Bounce button14 = Bounce(14, 5);
Bounce button15 = Bounce(15, 5);
void setup() {
// MIDI rate
Serial.begin(31250);
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(15, INPUT_PULLUP);
pinMode(16, INPUT_PULLUP);
pinMode(17, INPUT_PULLUP);
pinMode(18, INPUT_PULLUP);
pinMode(19, INPUT_PULLUP);
pinMode(20, INPUT_PULLUP);
pinMode(21, INPUT_PULLUP);
pinMode(22, INPUT_PULLUP);
pinMode(23, INPUT_PULLUP);
pinMode(24, INPUT_PULLUP);
pinMode(25, INPUT_PULLUP);
pinMode(26, INPUT_PULLUP);
pinMode(27, INPUT_PULLUP);
}
void loop() {
// loop trough active inputs for knobs
for (i=0;i<analogInputs;i++){
// read current value at i-th input
inputAnalog = analogRead(i);
// if magnitude of difference is 8 or more...
if (abs(inputAnalog - iAlag) > 7){
// calc the CC value based on the raw value
ccValue = inputAnalog/8;
// send the MIDI
usbMIDI.sendControlChange(i, ccValue, 3);
// set raw reading to lagged array for next comparison
iAlag = inputAnalog;
}
delay(5); // limits MIDI messages to reasonable number
}
// Push Button code
button0.update();
button1.update();
button2.update();
button3.update();
button4.update();
button5.update();
button6.update();
button7.update();
button8.update();
button9.update();
button10.update();
button11.update();
button12.update();
button13.update();
button14.update();
button15.update();
if (button0.fallingEdge())
{
usbMIDI.sendControlChange(cc0, cc_on, 3);
}
if (button1.fallingEdge())
{
usbMIDI.sendControlChange(cc1, cc_on, 3);
}
if (button2.fallingEdge())
{
usbMIDI.sendControlChange(cc2, cc_on, 3);
}
if (button3.fallingEdge())
{
usbMIDI.sendControlChange(cc3, cc_on, 3);
}
if (button4.fallingEdge())
{
usbMIDI.sendControlChange(cc4, cc_on, 3);
{
if (button5.fallingEdge())
{
usbMIDI.sendControlChange(cc5, cc_on, 3);
{
if (button6.fallingEdge())
{
usbMIDI.sendControlChange(cc6, cc_on, 3);
{
if (button7.fallingEdge())
{
usbMIDI.sendControlChange(cc7, cc_on, 3);
{
if (button8.fallingEdge())
{
usbMIDI.sendControlChange(cc8, cc_on, 3);
{
if (button9.fallingEdge())
{
usbMIDI.sendControlChange(cc9, cc_on, 3);
{
if (button10.fallingEdge())
{
usbMIDI.sendControlChange(cc10, cc_on, 3);
{
if (button11.fallingEdge())
{
usbMIDI.sendControlChange(cc11, cc_on, 3);
{
if (button12.fallingEdge())
{
usbMIDI.sendControlChange(cc12, cc_on, 3);
{
if (button13.fallingEdge())
{
usbMIDI.sendControlChange(cc13, cc_on, 3);
{
if (button14.fallingEdge())
{
usbMIDI.sendControlChange(cc14, cc_on, 3);
{
if (button15.fallingEdge())
{
usbMIDI.sendControlChange(cc15, cc_on, 3);
{
if (button0.risingEdge())
{
usbMIDI.sendControlChange(cc0, cc_off, 3);
}
if (button1.risingEdge())
{
usbMIDI.sendControlChange(cc1, cc_off, 3);
}
if (button2.risingEdge())
{
usbMIDI.sendControlChange(cc2, cc_off, 3);
}
if (button3.risingEdge())
{
usbMIDI.sendControlChange(cc3, cc_off, 3);
}
if (button4.risingEdge())
{
usbMIDI.sendControlChange(cc4, cc_off, 3);
}
if (button5.risingEdge())
{
usbMIDI.sendControlChange(cc5, cc_off, 3);
}
if (button6.risingEdge())
{
usbMIDI.sendControlChange(cc6, cc_off, 3);
}
if (button7.risingEdge())
{
usbMIDI.sendControlChange(cc7, cc_off, 3);
}
if (button8.risingEdge())
{
usbMIDI.sendControlChange(cc8, cc_off, 3);
}
if (button9.risingEdge())
{
usbMIDI.sendControlChange(cc9, cc_off, 3);
}
if (button10.risingEdge())
{
usbMIDI.sendControlChange(cc10, cc_off, 3);
}
if (button11.risingEdge())
{
usbMIDI.sendControlChange(cc11, cc_off, 3);
}
if (button12.risingEdge())
{
usbMIDI.sendControlChange(cc12, cc_off, 3);
}
if (button13.risingEdge())
{
usbMIDI.sendControlChange(cc13, cc_off, 3);
}
if (button14.risingEdge())
{
usbMIDI.sendControlChange(cc14, cc_off, 3);
}
if (button15.risingEdge())
{
usbMIDI.sendControlChange(cc15, cc_off, 3);
}
}
Any help is greatly appreciated.
thanks
James