Hey there,
after observing many posts and many many applications of the Teensy, I tried to go on by myself in this cruel world.
That was quite successful, thanks to this forum and the great things I learned here.
Until now...
I have two codes that work separately that I took here and adapt or not to my needs.
The thing is now I want to mix them to finally have exactly what I need.
The one on the left is good, but I need to use the one on the right to "map" perfectly all my 8 analog inputs as it does for only one.
I quite see how to mix them but hardly tried for two days now, and I must admit that I am not good enough at coding to do that.
Is there any kind people that may help me?
The values on the "map" of the right sketch are the ones I want to use for all the 8 analog inputs. That for sending MIDI(each analog input on its own CC), as it is done on the two sketches.
I know this doesn't look natural to do that as I assume you may understand why I am using the Teensy. But, trust me, this is the final solution...
In advance, thank you very very much, you'll save my week!
[td]#define THRESHOLD 14
int pot = 1;
int potbefore = 0;
void setup()
{
}
int update_current( int raw )
{
static int current = THRESHOLD;
int delta = raw - current;
if ( delta <= -THRESHOLD )
current = raw + THRESHOLD;
if ( delta >= THRESHOLD )
current = raw - THRESHOLD;
return current;
}
void loop() {
int raw = analogRead(pot);
int current = update_current( raw );
int scaled = map( current, 45, 990, 0, 127);
/* Serial.print ("current outside of if:"); Serial.println (current, DEC); Serial.print ("potbef outside of if:"); Serial.println (potbef, DEC); */
if (scaled != potbefore) {
usbMIDI.sendControlChange(1, scaled, 1);
potbefore = scaled;
}
[/td]
after observing many posts and many many applications of the Teensy, I tried to go on by myself in this cruel world.
That was quite successful, thanks to this forum and the great things I learned here.
Until now...
I have two codes that work separately that I took here and adapt or not to my needs.
The thing is now I want to mix them to finally have exactly what I need.
The one on the left is good, but I need to use the one on the right to "map" perfectly all my 8 analog inputs as it does for only one.
I quite see how to mix them but hardly tried for two days now, and I must admit that I am not good enough at coding to do that.
Is there any kind people that may help me?
The values on the "map" of the right sketch are the ones I want to use for all the 8 analog inputs. That for sending MIDI(each analog input on its own CC), as it is done on the two sketches.
I know this doesn't look natural to do that as I assume you may understand why I am using the Teensy. But, trust me, this is the final solution...
In advance, thank you very very much, you'll save my week!
#include <Bounce.h> // define how many pots are active up to number of available analog inputs #define analogInputs 8 // 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; Bounce button0 = Bounce(0, 3); Bounce button1 = Bounce(1, 3); Bounce button2 = Bounce(2, 3); Bounce button3 = Bounce(3, 3); Bounce button4 = Bounce(4, 3); Bounce button5 = Bounce(5, 3); Bounce button6 = Bounce(6, 3); Bounce button7 = Bounce(7, 3); Bounce button8 = Bounce(8, 3); Bounce button9 = Bounce(9, 3); Bounce button10 = Bounce(10, 3); 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(8, INPUT_PULLUP); pinMode(9, INPUT_PULLUP); pinMode(10, 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(); if (button0.fallingEdge()) { usbMIDI.sendNoteOn(50, 90, 10); } if (button1.fallingEdge()) { usbMIDI.sendNoteOn(51, 90, 10); } if (button2.fallingEdge()) { usbMIDI.sendNoteOn(52, 90, 10); } if (button3.fallingEdge()) { usbMIDI.sendNoteOn(53, 90, 10); } if (button4.fallingEdge()) { usbMIDI.sendNoteOn(54, 90, 10); } if (button5.fallingEdge()) { usbMIDI.sendNoteOn(55, 90, 10); } if (button6.fallingEdge()) { usbMIDI.sendNoteOn(56, 90, 10); } if (button7.fallingEdge()) { usbMIDI.sendNoteOn(57, 90, 10); } if (button8.fallingEdge()) { usbMIDI.sendNoteOn(58, 90, 10); } if (button9.fallingEdge()) { usbMIDI.sendNoteOn(59, 90, 10); } if (button10.fallingEdge()) { usbMIDI.sendNoteOn(60, 90, 10); } } |
[td]#define THRESHOLD 14
int pot = 1;
int potbefore = 0;
void setup()
{
}
int update_current( int raw )
{
static int current = THRESHOLD;
int delta = raw - current;
if ( delta <= -THRESHOLD )
current = raw + THRESHOLD;
if ( delta >= THRESHOLD )
current = raw - THRESHOLD;
return current;
}
void loop() {
int raw = analogRead(pot);
int current = update_current( raw );
int scaled = map( current, 45, 990, 0, 127);
/* Serial.print ("current outside of if:"); Serial.println (current, DEC); Serial.print ("potbef outside of if:"); Serial.println (potbef, DEC); */
if (scaled != potbefore) {
usbMIDI.sendControlChange(1, scaled, 1);
potbefore = scaled;
}
[/td]