Hey guys!!
So, I´ve been building a MIDI console to controle DAW with arduino uno. I have a code that already works but in a predetermined channel. As I would like to have more functionalities from the console than the UNO can give me; I mean I´m limited in 5 analog pins, so I could only use 5 faders and I would like to be able to use them in more than 5 tracks. One solution would be to change the channel and re-assign the potentiometer in that channel to other track. So, is there a simple way that I could assign a push-button to change the MIDI channels once pushed (e.g. pushed once --> channel 2; push again --> 3 and then go back to 1) so I could re-assign the potentiometers and re-use the same code? I mean re-use in the sense that I want the buttons and pots to work exactly in the same way in the other channels. I only want to have more "banks". Is that clear?
Well the code is as follows:
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();const int NButtons = 4;
const int button[NButtons] = {2,3,4,5};
int buttonCState[NButtons] = {0};
int buttonPState[NButtons] = {0};const int NPots = 1;
const int pot[NPots] = {A0};
int potCState[NPots] = {0};
int potPState[NPots] = {0};
int potVar = 0;byte midiCh = 1;
byte note = 36;
byte cc = 1;int TIMEOUT = 300;
int varThreshold = 4;
boolean potMoving = true;
unsigned long pTime[NPots] = {0};
unsigned long timer[NPots] = {0};void setup () {
MIDI.begin();
//Serial Connection
Serial.begin(115200);
//Initialize Digital Pins as inputs
for (int i=0; i<NButtons; i++){
pinMode(button*, INPUT_PULLUP);*
}*
// pinMode(button[3], INPUT); //pino 13//Initialize Analog Pins as inputs*
for (int i=0; i<NPots; i++){*
_ pinMode(pot*, INPUT);_
_ }*_}
void loop () {* for (int i=0; i<NButtons; i++) {*
buttonCState = digitalRead(button*);*
* }*
* buttonCState[12] = !buttonCState[12];** for (int i=0; i<NButtons; i++) {*
if (buttonCState != buttonPState*) {*
_ if(buttonCState == LOW) {
MIDI.sendNoteOn(note+i, 127, midiCh);
buttonPState = buttonCState*;*
* }
else {
MIDI.sendNoteOn(note+i, 0, midiCh);_
buttonPState _= buttonCState;
}
}*_* }*
* for (int i=0; i<NPots; i++) { // le todas entradas analogicas utilizadas*
potCState = analogRead(pot*);*
* }** for (int i=0; i<NPots; i++) {*
potVar = abs(potCState - potPState*);*
* if (potVar >= varThreshold) { *
_ pTime = millis();
* }_
timer _= millis() - pTime;
if (timer < TIMEOUT) {
potMoving = true;
}
else {
potMoving = false;
}
if (potMoving == true) {
MIDI.sendControlChange(cc+i, map(potCState, 0, 1023, 0, 127), midiCh);_
potPState _= potCState;
}
}*_}[/quote]
Many thanks in advance!
Marcos