Hi there,
I'm new here and to teensy so don't really have a clue what I'm talking about but I'm trying to make a midi controller through teensy 3.6 for 20 pots and 14 buttons/switches, so far I've managed to successfully code the switches but don't really have a clue about the pots. I've tried various bits of ode from the internet but haven't managed to get them to do what i want!
#include <Bounce.h>
// cc values for buttons
int cc_off = 0;
int cc_on = 127;
// map buttons to cc for button
int cc0 = 51;
int cc1 = 52;
int cc2 = 53;
int cc3 = 54;
int cc4 = 55;
int cc5 = 56;
int cc6 = 57;
int cc7 = 58;
int cc8 = 59;
int cc9 = 60;
int cc10 = 61;
int cc11 = 62;
int cc12 = 63;
int cc13 = 64;
Bounce button0 = Bounce(0, 13);
Bounce button1 = Bounce(1, 13); // 5 = 5 ms debounce time
Bounce button2 = Bounce(2, 13); // which is appropriate for good
Bounce button3 = Bounce(3, 13); // quality mechanical pushbuttons
Bounce button4 = Bounce(4, 13);
Bounce button5 = Bounce(5, 13); // if a button is too "sensitive"
Bounce button6 = Bounce(6, 13); // to rapid touch, you can
Bounce button7 = Bounce(7, 13); // increase this time.
Bounce button8 = Bounce(8, 13);
Bounce button9 = Bounce(9, 13);
Bounce button10 = Bounce(10, 13);
Bounce button11 = Bounce(11, 13);
Bounce button12 = Bounce(12, 13);
Bounce button13 = Bounce(13, 13);
void setup() {
// Configure the pins for input mode with pullup resistors.
// The pushbuttons connect from each pin to ground. When
// the button is pressed, the pin reads LOW because the button
// shorts it to ground. When released, the pin reads HIGH
// because the pullup resistor connects to +5 volts inside
// the chip. LOW for "on", and HIGH for "off" may seem
// backwards, but using the on-chip pullup resistors is very
// convenient. The scheme is called "active low", and it's
// very commonly used in electronics... so much that the chip
// has built-in pullup resistors!
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); // Teensy++ 2.0 LED, may need 1k resistor pullup
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(13, 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); // Teensy++ 2.0 LED, may need 1k resistor 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);
pinMode(28, INPUT_PULLUP);
pinMode(29, INPUT_PULLUP);
pinMode(30, INPUT_PULLUP);
pinMode(31, INPUT_PULLUP);
pinMode(32, INPUT_PULLUP);
pinMode(33, INPUT_PULLUP);
}
void loop() {
// 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();
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 (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);
}
}
Thats my code so far, it works fine for the buttons, this is the closest code for working i could find for the pots:
// define how many pots are active up to number of available analog inputs
#define analogInputs 20
// 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;
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
}
}
its the only thing i could actually get a reading on, but when i run it through MainStage it has lots of interference and cc5 constantly flicks between 90-95! Which somewhat breaks it and my computer cant process it all in time, the other knobs work but only halfway, when the pot is on min and max it translates cc to 0 and middle is 80, i just want a 0-127 as i turn the pot up, does anyone know how to fix all of these?
I'm new here and to teensy so don't really have a clue what I'm talking about but I'm trying to make a midi controller through teensy 3.6 for 20 pots and 14 buttons/switches, so far I've managed to successfully code the switches but don't really have a clue about the pots. I've tried various bits of ode from the internet but haven't managed to get them to do what i want!
#include <Bounce.h>
// cc values for buttons
int cc_off = 0;
int cc_on = 127;
// map buttons to cc for button
int cc0 = 51;
int cc1 = 52;
int cc2 = 53;
int cc3 = 54;
int cc4 = 55;
int cc5 = 56;
int cc6 = 57;
int cc7 = 58;
int cc8 = 59;
int cc9 = 60;
int cc10 = 61;
int cc11 = 62;
int cc12 = 63;
int cc13 = 64;
Bounce button0 = Bounce(0, 13);
Bounce button1 = Bounce(1, 13); // 5 = 5 ms debounce time
Bounce button2 = Bounce(2, 13); // which is appropriate for good
Bounce button3 = Bounce(3, 13); // quality mechanical pushbuttons
Bounce button4 = Bounce(4, 13);
Bounce button5 = Bounce(5, 13); // if a button is too "sensitive"
Bounce button6 = Bounce(6, 13); // to rapid touch, you can
Bounce button7 = Bounce(7, 13); // increase this time.
Bounce button8 = Bounce(8, 13);
Bounce button9 = Bounce(9, 13);
Bounce button10 = Bounce(10, 13);
Bounce button11 = Bounce(11, 13);
Bounce button12 = Bounce(12, 13);
Bounce button13 = Bounce(13, 13);
void setup() {
// Configure the pins for input mode with pullup resistors.
// The pushbuttons connect from each pin to ground. When
// the button is pressed, the pin reads LOW because the button
// shorts it to ground. When released, the pin reads HIGH
// because the pullup resistor connects to +5 volts inside
// the chip. LOW for "on", and HIGH for "off" may seem
// backwards, but using the on-chip pullup resistors is very
// convenient. The scheme is called "active low", and it's
// very commonly used in electronics... so much that the chip
// has built-in pullup resistors!
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); // Teensy++ 2.0 LED, may need 1k resistor pullup
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(13, 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); // Teensy++ 2.0 LED, may need 1k resistor 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);
pinMode(28, INPUT_PULLUP);
pinMode(29, INPUT_PULLUP);
pinMode(30, INPUT_PULLUP);
pinMode(31, INPUT_PULLUP);
pinMode(32, INPUT_PULLUP);
pinMode(33, INPUT_PULLUP);
}
void loop() {
// 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();
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 (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);
}
}
Thats my code so far, it works fine for the buttons, this is the closest code for working i could find for the pots:
// define how many pots are active up to number of available analog inputs
#define analogInputs 20
// 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;
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
}
}
its the only thing i could actually get a reading on, but when i run it through MainStage it has lots of interference and cc5 constantly flicks between 90-95! Which somewhat breaks it and my computer cant process it all in time, the other knobs work but only halfway, when the pot is on min and max it translates cc to 0 and middle is 80, i just want a 0-127 as i turn the pot up, does anyone know how to fix all of these?