You are on page 1of 17

#include <MIDI.

h>
#include "Controller.h"

//***KEYPAD***************************************************
#include <Keypad.h>

const byte ROWS = 4; //four rows


const byte COLS = 4; //four columns

char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};

byte rowPins[ROWS] = {50, 46, 42, 38}; //connect to the row pinouts of
the keypad
byte colPins[COLS] = {34, 30, 26, 22}; //connect to the column pinouts of
the keypad

Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins,


ROWS, COLS);
//************************************************************
//*****lcd 7 seg 4 dig****************************************
byte Digit[16][8] =
{ { 1,1,1,1,1,1,0,0 }, // 0
{ 0,1,1,0,0,0,0,0 }, // 1
{ 1,1,0,1,1,0,1,0 }, // 2
{ 1,1,1,1,0,0,1,0 }, // 3
{ 0,1,1,0,0,1,1,0 }, // 4
{ 1,0,1,1,0,1,1,0 }, // 5
{ 1,0,1,1,1,1,1,0 }, // 6
{ 1,1,1,0,0,0,0,0 }, // 7
{ 1,1,1,1,1,1,1,0 }, // 8
{ 1,1,1,0,0,1,1,0 }, // 9
{ 1,1,1,0,1,1,1,0 }, // A
{ 0,0,1,1,1,1,1,0 }, // B
{ 1,0,0,1,1,1,0,0 }, // C
{ 0,1,1,1,1,0,1,0 }, // D
{ 1,0,0,1,1,1,1,0 }, // E
{ 1,0,0,0,1,1,1,0 } // F
};
//************************************************************
/*************************************************************
MIDI CONTROLLER

by Notes and Volts


www.notesandvolts.com

Version 1.2 **Arduino UNO ONLY!**


*************************************************************/

MIDI_CREATE_DEFAULT_INSTANCE();

//************************************************************
//***SET THE NUMBER OF CONTROLS USED**************************
//************************************************************
//---How many buttons are connected directly to pins?---------
byte NUMBER_BUTTONS = 0;
//---How many potentiometers are connected directly to pins?--
byte NUMBER_POTS = 16;
//---How many buttons are connected to a multiplexer?---------
byte NUMBER_MUX_BUTTONS = 0;
//---How many potentiometers are connected to a multiplexer?--
byte NUMBER_MUX_POTS = 0;
//************************************************************

//***ANY MULTIPLEXERS? (74HC4067)************************************


//MUX address pins must be connected to Arduino UNO pins 2,3,4,5
//A0 = PIN2, A1 = PIN3, A2 = PIN4, A3 = PIN5
//*******************************************************************
//Mux NAME (OUTPUT PIN, , How Many Mux Pins?(8 or 16) , Is It Analog?);

//Mux M1(10, 16, false); //Digital multiplexer on Arduino pin 10


//Mux M2(A0, 8, true); //Analog multiplexer on Arduino analog pin A0
//*******************************************************************

//***DEFINE DIRECTLY CONNECTED POTENTIOMETERS************************


//Pot (Pin Number, Command, CC Control (or MSB), CC Control2 (or LSB),
Channel Number)
//** Command parameter 0=CC 1=NRpN **

Pot PO1(A0, 0, 0, 0, 1); // 14


Pot PO2(A1, 0, 0, 0, 1); // 13
Pot PO3(A2, 0, 0, 0, 1); // 15
Pot PO4(A3, 0, 0, 0, 1); // 16
Pot PO5(A4, 0, 0, 0, 1); // 12
Pot PO6(A5, 0, 0, 0, 1); // 09
Pot PO7(A6, 0, 0, 0, 1); // 11
Pot PO8(A7, 0, 0, 0, 1); // 10
Pot PO9(A8, 0, 0, 0, 1); // 04
Pot PO10(A9, 0, 0, 0, 1); // 01
Pot PO11(A10, 0, 0, 0, 1); // 02
Pot PO12(A11, 0, 0, 0, 1); // 07
Pot PO13(A12, 0, 0, 0, 1); // 03
Pot PO14(A13, 0, 0, 0, 1); // 05
Pot PO15(A14, 0, 0, 0, 1); // 08
Pot PO16(A15, 0, 0, 0, 1); // 06
//*******************************************************************
//Add pots used to array below like this-> Pot *POTS[] {&PO1, &PO2,
&PO3, &PO4, &PO5, &PO6};
Pot *POTS[] {&PO1, &PO2, &PO3, &PO4, &PO5, &PO6, &PO7, &PO8, &PO9, &PO10,
&PO11, &PO12, &PO13, &PO14, &PO15, &PO16};
//*******************************************************************

//***DEFINE DIRECTLY CONNECTED BUTTONS*******************************


//Button (Pin Number, Command, Note Number (or MSB), Value2 (or LSB),
Channel, Debounce Time)
//** Command parameter 0=NOTE 1=CC 2=Toggle CC 3=NRpN **

//Button BU1(7, 0, 64, 0, 1, 5 );


//Button BU2(6, 1, 71, 0, 1, 5 );
//Button BU3(4, 0, 64, 0, 1, 5 ); //nota 64
//Button BU4(5, 0, 60, 0, 1, 5 ); //nota 60
//Button BU5(6, 3, 60, 3, 1, 5 ); //nrpn LFO Delay
//Button BU6(7, 40, 76, 0, 1, 5 );
//Button BU7(8, 1, 64, 0, 1, 5 );
//Button BU8(9, 2, 64, 0, 1, 5 );
//*******************************************************************
//Add buttons used to array below like this-> Button *BUTTONS[] {&BU1,
&BU2, &BU3, &BU4, &BU5, &BU6, &BU7, &BU8};
Button *BUTTONS[] {};
//*******************************************************************

//***DEFINE BUTTONS CONNECTED TO MULTIPLEXER*************************


//Button::Button(Mux mux, byte muxpin, byte command, byte value, byte
channel, byte debounce)
//** Command parameter 0=NOTE 1=CC 2=Toggle CC **

//Button MBU1(M1, 0, 0, 70, 1, 5);


//Button MBU2(M1, 1, 1, 71, 1, 5);
//Button MBU3(M1, 2, 2, 72, 1, 5);
//Button MBU4(M1, 3, 0, 73, 1, 5);
//Button MBU5(M1, 4, 0, 74, 1, 5);
//Button MBU6(M1, 5, 0, 75, 1, 5);
//Button MBU7(M1, 6, 0, 76, 1, 5);
//Button MBU8(M1, 7, 0, 77, 1, 5);
//Button MBU9(M1, 8, 0, 78, 1, 5);
//Button MBU10(M1, 9, 0, 79, 1, 5);
//Button MBU11(M1, 10, 0, 80, 1, 5);
//Button MBU12(M1, 11, 0, 81, 1, 5);
//Button MBU13(M1, 12, 0, 82, 1, 5);
//Button MBU14(M1, 13, 0, 83, 1, 5);
//Button MBU15(M1, 14, 0, 84, 1, 5);
//Button MBU16(M1, 15, 0, 85, 1, 5);
//*******************************************************************
////Add multiplexed buttons used to array below like this-> Button
*MUXBUTTONS[] {&MBU1, &MBU2, &MBU3, &MBU4, &MBU5, &MBU6.....};
Button *MUXBUTTONS[] {};

//*******************************************************************

//***DEFINE POTENTIOMETERS CONNECTED TO MULTIPLEXER*******************


//Pot::Pot(Mux mux, byte muxpin, byte command, byte control, byte
control2, byte channel)
//**Command parameter is for future use 0=CC 1=NRpN **

//Pot MPO1(M2, 0, 1, 0, 76, 1);


//Pot MPO2(M2, 5, 0, 19, 0, 1);
//Pot MPO3(M2, 2, 0, 72, 0, 1);
//Pot MPO4(M2, 3, 0, 55, 0, 2);
//Pot MPO5(M2, 4, 0, 50, 0, 1);
//Pot MPO6(M2, 5, 0, 55, 0, 2);
//Pot MPO7(M2, 6, 0, 50, 0, 1);
//Pot MPO8(M2, 7, 0, 55, 0, 2);
//Pot MPO9(M2, 8, 0, 50, 0, 1);
//Pot MPO10(M2, 9, 0, 55, 0, 2);
//Pot MPO11(M2, 10, 0, 50, 0, 1);
//Pot MPO12(M2, 11, 0, 55, 0, 2);
//Pot MPO13(M2, 12, 0, 50, 0, 1);
//Pot MPO14(M2, 13, 0, 55, 0, 2);
//Pot MPO15(M2, 14, 0, 50, 0, 1);
//Pot MPO16(M2, 15, 0, 55, 0, 2);
//*******************************************************************
//Add multiplexed pots used to array below like this-> Pot *MUXPOTS[]
{&MPO1, &MPO2, &MPO3, &MPO4, &MPO5, &MPO6.....};
Pot *MUXPOTS[] {};
//*******************************************************************

///////////////////////////////////////////
int ledPin0 = 13;

void setup() {
MIDI.begin(MIDI_CHANNEL_OFF);
pinMode(ledPin0, OUTPUT);

for (int j= 2; j<13; j++)


//for (int j= 2; j<12; j++)
pinMode(j, OUTPUT);
}

void loop() {

char datoKey = customKeypad.getKey();


if (datoKey){
for (int i = 0; i < NUMBER_POTS; i = i + 1) {
POTS[i]->Pcommand = 0;}

if (datoKey == '0'){ // Osc1


POTS[0]->Pcontrol = 18; //14 Comm FixTranspose
POTS[1]->Pcontrol = 17; //13 Comm Phase
POTS[2]->Pcontrol = 76; //15 Comm VibratoSpeed
POTS[3]->Pcontrol = 77; //16 Comm VibratoDepth
POTS[4]->Pcontrol = 16; //12 Comm Drift
POTS[5]->Pcontrol = 26; //9 Semi
POTS[6]->Pcontrol = 0; //11
POTS[7]->Pcontrol = 27; //10 Cents
POTS[8]->Pcontrol = 22; //4 Vsync
POTS[9]->Pcontrol = 19; //1 Waveform
POTS[10]->Pcontrol = 20; //2 WTint
POTS[11]->Pcontrol = 25; //7 DnsDtn
POTS[12]->Pcontrol = 21; //3 PW/Indx
POTS[13]->Pcontrol = 23; //5 Hard
POTS[14]->Pcontrol = 28; //8 PitchBend
POTS[15]->Pcontrol = 24; //6 Dense
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == '1'){ // Osc2
POTS[0]->Pcontrol = 18; //14 Comm FixTranspose
POTS[1]->Pcontrol = 17; //13 Comm Phase
POTS[2]->Pcontrol = 76; //15 Comm VibratoSpeed
POTS[3]->Pcontrol = 77; //16 Comm VibratoDepth
POTS[4]->Pcontrol = 16; //12 Comm Drift
POTS[5]->Pcontrol = 38; //9
POTS[6]->Pcontrol = 0; //11
POTS[7]->Pcontrol = 39; //10
POTS[8]->Pcontrol = 33; //4
POTS[9]->Pcontrol = 29; //1
POTS[10]->Pcontrol = 30; //2
POTS[11]->Pcontrol = 36; //7
POTS[12]->Pcontrol = 31; //3
POTS[13]->Pcontrol = 34; //5
POTS[14]->Pcontrol = 40; //8
POTS[15]->Pcontrol = 35; //6
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == '2'){ // Osc3
POTS[0]->Pcontrol = 18; //14 Comm FixTranspose
POTS[1]->Pcontrol = 17; //13 Comm Phase
POTS[2]->Pcontrol = 76; //15 Comm VibratoSpeed
POTS[3]->Pcontrol = 77; //16 Comm VibratoDepth
POTS[4]->Pcontrol = 16; //12 Comm Drift
POTS[5]->Pcontrol = 48; //9
POTS[6]->Pcontrol = 0; //11
POTS[7]->Pcontrol = 49; //10
POTS[8]->Pcontrol = 44; //4
POTS[9]->Pcontrol = 41; //1
POTS[10]->Pcontrol = 42; //2
POTS[11]->Pcontrol = 47; //7
POTS[12]->Pcontrol = 43; //3
POTS[13]->Pcontrol = 45; //5
POTS[14]->Pcontrol = 50; //8
POTS[15]->Pcontrol = 46; //6
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == '3'){ // Mixer
POTS[0]->Pcommand = 1; //14 nrpn
POTS[0]->Pcontrol = 1; //14 ModMtrx02Lvl
POTS[0]->Pcontrol2 = 91; //14
POTS[1]->Pcommand = 1; //13 nrpn
POTS[1]->Pcontrol = 1; //13 ModMtrx01Lvl
POTS[1]->Pcontrol2 = 86; //13
POTS[2]->Pcontrol = 0; //15
POTS[3]->Pcontrol = 0; //16
POTS[4]->Pcontrol = 87; //12 Env2ToFreq2
POTS[5]->Pcontrol = 58; //9 PreFx
POTS[6]->Pcontrol = 79; //11 Env2ToFreq1
POTS[7]->Pcontrol = 59; //10 PostFx
POTS[8]->Pcontrol = 56; //4 NoiseLvl
POTS[9]->Pcontrol = 51; //1 Osc01Lvl
POTS[10]->Pcontrol = 52; //2 Osc02Lvl
POTS[11]->Pcontrol = 0; //7
POTS[12]->Pcontrol = 53; //3 Osc03Lvl
POTS[13]->Pcontrol = 54; //5 Ring13
POTS[14]->Pcontrol = 57; //8 NoiseType
POTS[15]->Pcontrol = 55; //6 Ring23
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == '4'){
POTS[0]->Pcontrol = 116; //14 ENV1 DECAYSLOPE
POTS[1]->Pcontrol = 115; //13 ENV1 ATTACKSLOPE
POTS[2]->Pcontrol = 0; //15
POTS[3]->Pcontrol = 0; //16
POTS[4]->Pcontrol = 0; //12
POTS[5]->Pcontrol = 112; //9 ENV1 ATTACKTRACK
POTS[6]->Pcontrol = 114; //11 ENV1 LEVELTRACK
POTS[7]->Pcontrol = 113; //10 ENV1 DECAYTRACK
POTS[8]->Pcontrol = 72; //4 ENV1 RELEASE
POTS[9]->Pcontrol = 73; //1 ENV1 ATTACK
POTS[10]->Pcontrol = 75; //2 ENV1 DECAY
POTS[11]->Pcontrol = 110; //7 ENV1 SUSTAINTIME
POTS[12]->Pcontrol = 70; //3 ENV1 SUSTAIN
POTS[13]->Pcontrol = 108; //5 ENV1 VELOCITY
POTS[14]->Pcontrol = 111; //8 ENV1 ADREPEATS
POTS[15]->Pcontrol = 109; //6 ENV1 SUSTAINRATE
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == '5'){
POTS[0]->Pcommand = 1; // nrpn
POTS[0]->Pcontrol = 0; //14 ENV2 DECAYSLOPE
POTS[0]->Pcontrol2 = 12; //14
POTS[1]->Pcommand = 1; // nrpn
POTS[1]->Pcontrol = 0; //13 ENV2 ATTACKSLOPE
POTS[1]->Pcontrol2 = 11; //13
POTS[2]->Pcommand = 0; // nrpn
POTS[2]->Pcontrol = 0; //15
POTS[2]->Pcontrol2 = 0; //15
POTS[3]->Pcommand = 0; // nrpn
POTS[3]->Pcontrol = 0; //16
POTS[3]->Pcontrol2 = 0; //16
POTS[4]->Pcommand = 0; // nrpn
POTS[4]->Pcontrol = 0; //12
POTS[4]->Pcontrol2 = 0; //12
POTS[5]->Pcommand = 1; // nrpn
POTS[5]->Pcontrol = 0; //9 ENV2 ATTACKTRACK
POTS[5]->Pcontrol2 = 8; //9
POTS[6]->Pcommand = 1; // nrpn
POTS[6]->Pcontrol = 0; //11 ENV2 LEVELTRACK
POTS[6]->Pcontrol2 = 10; //11
POTS[7]->Pcommand = 1; // nrpn
POTS[7]->Pcontrol = 0; //10 ENV2 DECAYTRACK
POTS[7]->Pcontrol2 = 9; //10
POTS[8]->Pcommand = 1; // nrpn
POTS[8]->Pcontrol = 0; //4 ENV2 RELEASE
POTS[8]->Pcontrol2 = 4; //4
POTS[9]->Pcommand = 1; // nrpn
POTS[9]->Pcontrol = 0; //1 ENV2 ATTACK
POTS[9]->Pcontrol2 = 1; //1
POTS[10]->Pcommand = 1; // nrpn
POTS[10]->Pcontrol = 0; //2 ENV2 DECAY
POTS[10]->Pcontrol2 = 2; //2
POTS[11]->Pcommand = 1; // nrpn
POTS[11]->Pcontrol = 0; //7 ENV2 SUSTAINTIME
POTS[11]->Pcontrol2 = 6; //7
POTS[12]->Pcommand = 1; // nrpn
POTS[12]->Pcontrol = 0; //3 ENV2 SUSTAIN
POTS[12]->Pcontrol2 = 3; //3
POTS[13]->Pcommand = 1; // nrpn
POTS[13]->Pcontrol = 0; //5 ENV2 VELOCITY
POTS[13]->Pcontrol2 = 0; //5
POTS[14]->Pcommand = 1; // nrpn
POTS[14]->Pcontrol = 0; //8 ENV2 ADREPEATS
POTS[14]->Pcontrol2 = 7; //8
POTS[15]->Pcommand = 1; // nrpn
POTS[15]->Pcontrol = 0; //6 ENV2 SUSTAINRATE
POTS[15]->Pcontrol2 = 5; //6
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == '6'){
POTS[0]->Pcommand = 1; // nrpn
POTS[0]->Pcontrol = 0; //14 ENV3 DECAYSLOPE
POTS[0]->Pcontrol2 = 26; //14
POTS[1]->Pcommand = 1; // nrpn
POTS[1]->Pcontrol = 0; //13 ENV3 ATTACKSLOPE
POTS[1]->Pcontrol2 = 25; //13
POTS[2]->Pcommand = 0; // nrpn
POTS[2]->Pcontrol = 0; //15
POTS[2]->Pcontrol2 = 0; //15
POTS[3]->Pcommand = 0; // nrpn
POTS[3]->Pcontrol = 0; //16
POTS[3]->Pcontrol2 = 0; //16
POTS[4]->Pcommand = 0; // nrpn
POTS[4]->Pcontrol = 0; //12
POTS[4]->Pcontrol2 = 0; //12
POTS[5]->Pcommand = 1; // nrpn
POTS[5]->Pcontrol = 0; //9 ENV3 ATTACKTRACK
POTS[5]->Pcontrol2 = 22; //9
POTS[6]->Pcommand = 1; // nrpn
POTS[6]->Pcontrol = 0; //11 ENV3 LEVELTRACK
POTS[6]->Pcontrol2 = 24; //11
POTS[7]->Pcommand = 1; // nrpn
POTS[7]->Pcontrol = 0; //10 ENV3 DECAYTRACK
POTS[7]->Pcontrol2 = 23; //10
POTS[8]->Pcommand = 1; // nrpn
POTS[8]->Pcontrol = 0; //4 ENV3 RELEASE
POTS[8]->Pcontrol2 = 18; //4
POTS[9]->Pcommand = 1; // nrpn
POTS[9]->Pcontrol = 0; //1 ENV3 ATTACK
POTS[9]->Pcontrol2 = 15; //1
POTS[10]->Pcommand = 1; // nrpn
POTS[10]->Pcontrol = 0; //2 ENV3 DECAY
POTS[10]->Pcontrol2 = 16; //2
POTS[11]->Pcommand = 1; // nrpn
POTS[11]->Pcontrol = 0; //7 ENV3 SUSTAINTIME
POTS[11]->Pcontrol2 = 20; //7
POTS[12]->Pcommand = 1; // nrpn
POTS[12]->Pcontrol = 0; //3 ENV3 SUSTAIN
POTS[12]->Pcontrol2 = 17; //3
POTS[13]->Pcommand = 1; // nrpn
POTS[13]->Pcontrol = 0; //5 ENV3 DELAY
POTS[13]->Pcontrol2 = 14; //5
POTS[14]->Pcommand = 1; // nrpn
POTS[14]->Pcontrol = 0; //8 ENV3 ADREPEATS
POTS[14]->Pcontrol2 = 21; //8
POTS[15]->Pcommand = 1; // nrpn
POTS[15]->Pcontrol = 0; //6 ENV3 SUSTAINRATE
POTS[15]->Pcontrol2 = 19; //6
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == '7'){
POTS[0]->Pcontrol = 0; //14
POTS[1]->Pcontrol = 0; //13
POTS[2]->Pcontrol = 0; //15
POTS[3]->Pcontrol = 0; //16
POTS[4]->Pcontrol = 0; //12
POTS[5]->Pcontrol = 0; //9
POTS[6]->Pcontrol = 0; //11
POTS[7]->Pcontrol = 0; //10
POTS[8]->Pcontrol = 0; //4
POTS[9]->Pcontrol = 0; //1
POTS[10]->Pcontrol = 0; //2
POTS[11]->Pcontrol = 0; //7
POTS[12]->Pcontrol = 0; //3
POTS[13]->Pcontrol = 0; //5
POTS[14]->Pcontrol = 0; //8
POTS[15]->Pcontrol = 0; //6
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == '8'){
POTS[0]->Pcontrol = 84; //14 FLT2 TRACK
POTS[1]->Pcontrol = 87; //13 FLT2 ENV2TOFREQ
POTS[2]->Pcontrol = 86; //15 FLT2 QNORM
POTS[3]->Pcontrol = 81; //16 FLT2 DRIVETYPE
POTS[4]->Pcontrol = 80; //12 FLT2 DRIVEAmmount
POTS[5]->Pcontrol = 83; //9 FLT2 FREQ
POTS[6]->Pcontrol = 82; //11 FLT2 TYPE
POTS[7]->Pcontrol = 85; //10 FLT2 RESONANCE
POTS[8]->Pcontrol = 63; //4 FLT1 DRIVEAmmount
POTS[9]->Pcontrol = 74; //1 FLT1 FREQ
POTS[10]->Pcontrol = 71; //2 FLT1 RESONANCE
POTS[11]->Pcontrol = 78; //7 FLT1 QNORM
POTS[12]->Pcontrol = 68; //3 FLT1 TYPE
POTS[13]->Pcontrol = 79; //5 FLT1 ENV2TOFREQ
POTS[14]->Pcontrol = 65; //8 FLT1 DRIVETYPE
POTS[15]->Pcontrol = 69; //6 FLT1 TRACK
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == '9'){
POTS[0]->Pcontrol = 0; //14
POTS[1]->Pcontrol = 0; //13
POTS[2]->Pcontrol = 0; //15
POTS[3]->Pcontrol = 0; //16
POTS[4]->Pcontrol = 0; //12
POTS[5]->Pcontrol = 0; //9
POTS[6]->Pcontrol = 0; //11
POTS[7]->Pcontrol = 0; //10
POTS[8]->Pcontrol = 0; //4
POTS[9]->Pcontrol = 0; //1
POTS[10]->Pcontrol = 0; //2
POTS[11]->Pcontrol = 0; //7
POTS[12]->Pcontrol = 0; //3
POTS[13]->Pcontrol = 0; //5
POTS[14]->Pcontrol = 0; //8
POTS[15]->Pcontrol = 0; //6
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == 'A'){
POTS[0]->Pcontrol = 0; //14
POTS[1]->Pcontrol = 0; //13
POTS[2]->Pcontrol = 0; //15
POTS[3]->Pcontrol = 0; //16
POTS[4]->Pcontrol = 0; //12
POTS[5]->Pcontrol = 0; //9
POTS[6]->Pcontrol = 0; //11
POTS[7]->Pcontrol = 0; //10
POTS[8]->Pcontrol = 0; //4
POTS[9]->Pcontrol = 0; //1
POTS[10]->Pcontrol = 0; //2
POTS[11]->Pcontrol = 0; //7
POTS[12]->Pcontrol = 0; //3
POTS[13]->Pcontrol = 0; //5
POTS[14]->Pcontrol = 0; //8
POTS[15]->Pcontrol = 0; //6
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == 'B'){
POTS[0]->Pcontrol = 0; //14
POTS[1]->Pcontrol = 0; //13
POTS[2]->Pcontrol = 0; //15
POTS[3]->Pcontrol = 0; //16
POTS[4]->Pcontrol = 0; //12
POTS[5]->Pcontrol = 0; //9
POTS[6]->Pcontrol = 0; //11
POTS[7]->Pcontrol = 0; //10
POTS[8]->Pcontrol = 0; //4
POTS[9]->Pcontrol = 0; //1
POTS[10]->Pcontrol = 0; //2
POTS[11]->Pcontrol = 0; //7
POTS[12]->Pcontrol = 0; //3
POTS[13]->Pcontrol = 0; //5
POTS[14]->Pcontrol = 0; //8
POTS[15]->Pcontrol = 0; //6
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == 'C'){
POTS[0]->Pcommand = 0; // nrpn
POTS[0]->Pcontrol = 0; //14
POTS[0]->Pcontrol2 = 0; //14
POTS[1]->Pcommand = 0; // nrpn
POTS[1]->Pcontrol = 0; //13
POTS[1]->Pcontrol2 = 0; //13
POTS[2]->Pcommand = 0; // nrpn
POTS[2]->Pcontrol = 0; //15
POTS[2]->Pcontrol2 = 0; //15
POTS[3]->Pcommand = 0; // nrpn
POTS[3]->Pcontrol = 0; //16
POTS[3]->Pcontrol2 = 0; //16
POTS[4]->Pcommand = 0; // nrpn
POTS[4]->Pcontrol = 0; //12
POTS[4]->Pcontrol2 = 0; //12
POTS[5]->Pcommand = 0; // nrpn
POTS[5]->Pcontrol = 0; //9
POTS[5]->Pcontrol2 = 0; //9
POTS[6]->Pcommand = 0; // nrpn
POTS[6]->Pcontrol = 0; //11
POTS[6]->Pcontrol2 = 0; //11
POTS[7]->Pcommand = 0; // nrpn
POTS[7]->Pcontrol = 0; //10
POTS[7]->Pcontrol2 = 0; //10
POTS[8]->Pcommand = 1; // nrpn
POTS[8]->Pcontrol = 0; //4 LFO1 RATESYNC
POTS[8]->Pcontrol2 = 77; //4
POTS[9]->Pcommand = 1; // nrpn
POTS[9]->Pcontrol = 0; //1 LFO1 WAVEFORM
POTS[9]->Pcontrol2 = 70; //1
POTS[10]->Pcommand = 1; // nrpn
POTS[10]->Pcontrol = 0; //2 LFO1 PHASEOFFSET
POTS[10]->Pcontrol2 = 71; //2
POTS[11]->Pcommand = 1; // nrpn
POTS[11]->Pcontrol = 0; //7 LFO1 DELAY
POTS[11]->Pcontrol2 = 74; //7
POTS[12]->Pcommand = 1; // nrpn
POTS[12]->Pcontrol = 0; //3 LFO1 RATE
POTS[12]->Pcontrol2 = 76; //3
POTS[13]->Pcommand = 1; // nrpn
POTS[13]->Pcontrol = 0; //5 LFO1 SLEWRATE
POTS[13]->Pcontrol2 = 72; //5
POTS[14]->Pcommand = 1; // nrpn
POTS[14]->Pcontrol = 0; //8 LFO1 DELAYSYNC
POTS[14]->Pcontrol2 = 75; //8
POTS[15]->Pcommand = 0; // nrpn
POTS[15]->Pcontrol = 0; //6
POTS[15]->Pcontrol2 = 0; //6
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == 'D'){
POTS[0]->Pcommand = 0; // nrpn
POTS[0]->Pcontrol = 0; //14
POTS[0]->Pcontrol2 = 0; //14
POTS[1]->Pcommand = 0; // nrpn
POTS[1]->Pcontrol = 0; //13
POTS[1]->Pcontrol2 = 0; //13
POTS[2]->Pcommand = 0; // nrpn
POTS[2]->Pcontrol = 0; //15
POTS[2]->Pcontrol2 = 0; //15
POTS[3]->Pcommand = 0; // nrpn
POTS[3]->Pcontrol = 0; //16
POTS[3]->Pcontrol2 = 0; //16
POTS[4]->Pcommand = 0; // nrpn
POTS[4]->Pcontrol = 0; //12
POTS[4]->Pcontrol2 = 0; //12
POTS[5]->Pcommand = 0; // nrpn
POTS[5]->Pcontrol = 0; //9
POTS[5]->Pcontrol2 = 0; //9
POTS[6]->Pcommand = 0; // nrpn
POTS[6]->Pcontrol = 0; //11
POTS[6]->Pcontrol2 = 0; //11
POTS[7]->Pcommand = 0; // nrpn
POTS[7]->Pcontrol = 0; //10
POTS[7]->Pcontrol2 = 0; //10
POTS[8]->Pcommand = 1; // nrpn
POTS[8]->Pcontrol = 0; //4 LFO2 RATESYNC
POTS[8]->Pcontrol2 = 86; //4
POTS[9]->Pcommand = 1; // nrpn
POTS[9]->Pcontrol = 0; //1 LFO2 WAVEFORM
POTS[9]->Pcontrol2 = 79; //1
POTS[10]->Pcommand = 1; // nrpn
POTS[10]->Pcontrol = 0; //2 LFO2 PHASEOFFSET
POTS[10]->Pcontrol2 = 80; //2
POTS[11]->Pcommand = 1; // nrpn
POTS[11]->Pcontrol = 0; //7 LFO2 DELAY
POTS[11]->Pcontrol2 = 83; //7
POTS[12]->Pcommand = 1; // nrpn
POTS[12]->Pcontrol = 0; //3 LFO2 RATE
POTS[12]->Pcontrol2 = 85; //3
POTS[13]->Pcommand = 1; // nrpn
POTS[13]->Pcontrol = 0; //5 LFO2 SLEWRATE
POTS[13]->Pcontrol2 = 81; //5
POTS[14]->Pcommand = 1; // nrpn
POTS[14]->Pcontrol = 0; //8 LFO2 DELAYSYNC
POTS[14]->Pcontrol2 = 84; //8
POTS[15]->Pcommand = 0; // nrpn
POTS[15]->Pcontrol = 0; //6
POTS[15]->Pcontrol2 = 0; //6
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == 'E'){
POTS[0]->Pcommand = 0; // nrpn
POTS[0]->Pcontrol = 0; //14
POTS[0]->Pcontrol2 = 0; //14
POTS[1]->Pcommand = 0; // nrpn
POTS[1]->Pcontrol = 0; //13
POTS[1]->Pcontrol2 = 0; //13
POTS[2]->Pcommand = 0; // nrpn
POTS[2]->Pcontrol = 0; //15
POTS[2]->Pcontrol2 = 0; //15
POTS[3]->Pcommand = 0; // nrpn
POTS[3]->Pcontrol = 0; //16
POTS[3]->Pcontrol2 = 0; //16
POTS[4]->Pcommand = 0; // nrpn
POTS[4]->Pcontrol = 0; //12
POTS[4]->Pcontrol2 = 0; //12
POTS[5]->Pcommand = 0; // nrpn
POTS[5]->Pcontrol = 0; //9
POTS[5]->Pcontrol2 = 0; //9
POTS[6]->Pcommand = 0; // nrpn
POTS[6]->Pcontrol = 0; //11
POTS[6]->Pcontrol2 = 0; //11
POTS[7]->Pcommand = 0; // nrpn
POTS[7]->Pcontrol = 0; //10
POTS[7]->Pcontrol2 = 0; //10
POTS[8]->Pcommand = 1; // nrpn
POTS[8]->Pcontrol = 0; //4 LFO2 RATESYNC
POTS[8]->Pcontrol2 = 95; //4
POTS[9]->Pcommand = 1; // nrpn
POTS[9]->Pcontrol = 0; //1 LFO2 WAVEFORM
POTS[9]->Pcontrol2 = 88; //1
POTS[10]->Pcommand = 1; // nrpn
POTS[10]->Pcontrol = 0; //2 LFO2 PHASEOFFSET
POTS[10]->Pcontrol2 = 89; //2
POTS[11]->Pcommand = 1; // nrpn
POTS[11]->Pcontrol = 0; //7 LFO2 DELAY
POTS[11]->Pcontrol2 = 92; //7
POTS[12]->Pcommand = 1; // nrpn
POTS[12]->Pcontrol = 0; //3 LFO2 RATE
POTS[12]->Pcontrol2 = 94; //3
POTS[13]->Pcommand = 1; // nrpn
POTS[13]->Pcontrol = 0; //5 LFO2 SLEWRATE
POTS[13]->Pcontrol2 = 90; //5
POTS[14]->Pcommand = 1; // nrpn
POTS[14]->Pcontrol = 0; //8 LFO2 DELAYSYNC
POTS[14]->Pcontrol2 = 93; //8
POTS[15]->Pcommand = 0; // nrpn
POTS[15]->Pcontrol = 0; //6
POTS[15]->Pcontrol2 = 0; //6
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}else if (datoKey == 'F'){
POTS[0]->Pcontrol = 0; //14
POTS[1]->Pcontrol = 0; //13
POTS[2]->Pcontrol = 0; //15
POTS[3]->Pcontrol = 0; //16
POTS[4]->Pcontrol = 0; //12
POTS[5]->Pcontrol = 0; //9
POTS[6]->Pcontrol = 0; //11
POTS[7]->Pcontrol = 0; //10
POTS[8]->Pcontrol = 0; //4
POTS[9]->Pcontrol = 0; //1
POTS[10]->Pcontrol = 0; //2
POTS[11]->Pcontrol = 0; //7
POTS[12]->Pcontrol = 0; //3
POTS[13]->Pcontrol = 0; //5
POTS[14]->Pcontrol = 0; //8
POTS[15]->Pcontrol = 0; //6
digitalWrite(ledPin0, LOW);
CalculaDigitos2(datoKey);
}
}
if (NUMBER_BUTTONS != 0) updateButtons();
if (NUMBER_POTS != 0) updatePots();
if (NUMBER_MUX_BUTTONS != 0) updateMuxButtons();
if (NUMBER_MUX_POTS != 0) updateMuxPots();
}

//*****************************************************************
void updateButtons() {

// Cycle through Button array


for (int i = 0; i < NUMBER_BUTTONS; i = i + 1) {
byte message = BUTTONS[i]->getValue();

// Button is pressed
if (message == 0) {
switch (BUTTONS[i]->Bcommand) {
case 0: //Note
MIDI.sendNoteOn(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
break;
case 1: //CC
MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]-
>Bchannel);
break;
case 2: //Toggle
if (BUTTONS[i]->Btoggle == 0) {
MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]-
>Bchannel);
BUTTONS[i]->Btoggle = 1;
}
else if (BUTTONS[i]->Btoggle == 1) {
MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]-
>Bchannel);
BUTTONS[i]->Btoggle = 0;
}
break;
case 3: //nrpn on off
MIDI.sendControlChange(99, BUTTONS[i]->Bvalue, BUTTONS[i]-
>Bchannel);
MIDI.sendControlChange(98, BUTTONS[i]->Bvalue2, BUTTONS[i]-
>Bchannel);
MIDI.sendControlChange(06, 127, 1);
break;
}
}

// Button is not pressed


if (message == 1) {
switch (BUTTONS[i]->Bcommand) {
case 0:
MIDI.sendNoteOff(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
break;
case 1:
MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]-
>Bchannel);
break;
case 3:
MIDI.sendControlChange(99, BUTTONS[i]->Bvalue, 1);
MIDI.sendControlChange(98, BUTTONS[i]->Bvalue2, 1);
MIDI.sendControlChange(06, 0, 1);
break;
}
}
}
}
//*******************************************************************
void updateMuxButtons() {

// Cycle through Mux Button array


for (int i = 0; i < NUMBER_MUX_BUTTONS; i = i + 1) {

MUXBUTTONS[i]->muxUpdate();
byte message = MUXBUTTONS[i]->getValue();

// Button is pressed
if (message == 0) {
switch (MUXBUTTONS[i]->Bcommand) {
case 0: //Note
MIDI.sendNoteOn(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]-
>Bchannel);
break;
case 1: //CC
MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 127,
MUXBUTTONS[i]->Bchannel);
break;
case 2: //Toggle
if (MUXBUTTONS[i]->Btoggle == 0) {
MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 127,
MUXBUTTONS[i]->Bchannel);
MUXBUTTONS[i]->Btoggle = 1;
}
else if (MUXBUTTONS[i]->Btoggle == 1) {
MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 0,
MUXBUTTONS[i]->Bchannel);
MUXBUTTONS[i]->Btoggle = 0;
}
break;
}
}
// Button is not pressed
if (message == 1) {
switch (MUXBUTTONS[i]->Bcommand) {
case 0:
MIDI.sendNoteOff(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]-
>Bchannel);
break;
case 1:
MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]-
>Bchannel);
break;
}
}
}
}
//***********************************************************************
/*void updatePots() {
for (int i = 0; i < NUMBER_POTS; i = i + 1) {
byte potmessage = POTS[i]->getValue();
if (potmessage != 255) MIDI.sendControlChange(POTS[i]->Pcontrol,
potmessage, POTS[i]->Pchannel);
}
}*/
void updatePots() {
for (int i = 0; i < NUMBER_POTS; i = i + 1) {
byte potmessage = POTS[i]->getValue();

if (potmessage != 255) {
switch (POTS[i]->Pcommand) {
case 0: //CC
if (POTS[i]->Pcontrol == 19 || POTS[i]->Pcontrol == 29 ||
POTS[i]->Pcontrol == 41) {
CalculaDigitos(potmessage/1.77);
MIDI.sendControlChange(POTS[i]->Pcontrol, (potmessage/1.77),
POTS[i]->Pchannel);
}else if(POTS[i]->Pcontrol == 28 || POTS[i]->Pcontrol == 40 ||
POTS[i]->Pcontrol == 50) {
MIDI.sendControlChange(POTS[i]->Pcontrol,
((potmessage/5.1)+52), POTS[i]->Pchannel);
CalculaDigitos((potmessage/5.1)+52);
}else if(POTS[i]->Pcontrol == 17) {
MIDI.sendControlChange(POTS[i]->Pcontrol, (potmessage/1.05),
POTS[i]->Pchannel);
CalculaDigitos(potmessage/1.05);
}else if(POTS[i]->Pcontrol == 57) {
MIDI.sendControlChange(POTS[i]->Pcontrol, (potmessage/31.75),
POTS[i]->Pchannel);
CalculaDigitos(potmessage/31.75);
}else if(POTS[i]->Pcontrol == 58 || POTS[i]->Pcontrol == 59) {
MIDI.sendControlChange(POTS[i]->Pcontrol,
((potmessage/4.23)+52), POTS[i]->Pchannel);
CalculaDigitos((potmessage/4.23)+52);
}else if(POTS[i]->Pcontrol == 60) {
MIDI.sendControlChange(POTS[i]->Pcontrol, (potmessage/21.2),
POTS[i]->Pchannel);
CalculaDigitos(potmessage/21.2);
}else if(POTS[i]->Pcontrol == 65 || POTS[i]->Pcontrol == 81) {
MIDI.sendControlChange(POTS[i]->Pcontrol, (potmessage/18.3),
POTS[i]->Pchannel);
CalculaDigitos(potmessage/18.3);
}else if(POTS[i]->Pcontrol == 68 || POTS[i]->Pcontrol == 82) {
MIDI.sendControlChange(POTS[i]->Pcontrol, (potmessage/9.1),
POTS[i]->Pchannel);
CalculaDigitos(potmessage/9.1);
}else{
MIDI.sendControlChange(POTS[i]->Pcontrol, potmessage,
POTS[i]->Pchannel);
CalculaDigitos(potmessage);
}
break;
case 1: //NRpN
if(POTS[i]->Pcontrol == 0 && POTS[i]->Pcontrol2 == 70 ||
POTS[i]->Pcontrol == 0 && POTS[i]->Pcontrol2 == 79 || POTS[i]->Pcontrol
== 0 && POTS[i]->Pcontrol2 == 88) {
MIDI.sendControlChange(99, POTS[i]->Pcontrol, POTS[i]-
>Pchannel);
MIDI.sendControlChange(98, POTS[i]->Pcontrol2, POTS[i]-
>Pchannel);
MIDI.sendControlChange(06, potmessage/3.35, POTS[i]-
>Pchannel);
CalculaDigitos(potmessage/3.35);
}else if(POTS[i]->Pcontrol == 0 && POTS[i]->Pcontrol2 == 75 ||
POTS[i]->Pcontrol == 0 && POTS[i]->Pcontrol2 == 77 || POTS[i]->Pcontrol
== 0 && POTS[i]->Pcontrol2 == 84 || POTS[i]->Pcontrol == 0 && POTS[i]-
>Pcontrol2 == 86 || POTS[i]->Pcontrol == 0 && POTS[i]->Pcontrol2 == 93 ||
POTS[i]->Pcontrol == 0 && POTS[i]->Pcontrol2 == 95) {
MIDI.sendControlChange(99, POTS[i]->Pcontrol, POTS[i]-
>Pchannel);
MIDI.sendControlChange(98, POTS[i]->Pcontrol2, POTS[i]-
>Pchannel);
MIDI.sendControlChange(06, potmessage/3.53, POTS[i]-
>Pchannel);
CalculaDigitos(potmessage/3.53);
}else{
MIDI.sendControlChange(99, POTS[i]->Pcontrol, POTS[i]-
>Pchannel);
MIDI.sendControlChange(98, POTS[i]->Pcontrol2, POTS[i]-
>Pchannel);
MIDI.sendControlChange(06, potmessage, POTS[i]->Pchannel);
CalculaDigitos(potmessage);
}
break;
}
}
}
}
/*//*********************************************************************
**
void updateMuxPots() {
for (int i = 0; i < NUMBER_MUX_POTS; i = i + 1) {
MUXPOTS[i]->muxUpdate();
byte potmessage = MUXPOTS[i]->getValue();
if (potmessage != 255) MIDI.sendControlChange(MUXPOTS[i]->Pcontrol,
potmessage, MUXPOTS[i]->Pchannel);
}
}*/
void updateMuxPots() {
for (int i = 0; i < NUMBER_MUX_POTS; i = i + 1) {
MUXPOTS[i]->muxUpdate();
byte potmessage = MUXPOTS[i]->getValue();

if (potmessage != 255) {
switch (MUXPOTS[i]->Pcommand) {
case 0: //CC
MIDI.sendControlChange(MUXPOTS[i]->Pcontrol, potmessage,
MUXPOTS[i]->Pchannel);
break;
case 1: //NRpN
MIDI.sendControlChange(99, MUXPOTS[i]->Pcontrol, MUXPOTS[i]-
>Pchannel);
MIDI.sendControlChange(98, MUXPOTS[i]->Pcontrol2, MUXPOTS[i]-
>Pchannel);
MIDI.sendControlChange(06, potmessage, MUXPOTS[i]->Pchannel);
break;
}
}
}
}
//**********************************************************************
void CalculaDigitos( int Num) {
int Digit0 = Num %10 ;
int Digit1 = (Num % 100) / 10;
int Digit2 = (Num % 1000) / 100 ;
int Digit3 = Num / 1000 ;

Display(3 , Digit3);
Display(2 , Digit2);
Display(1 , Digit1);
Display(0 , Digit0);
}
void CalculaDigitos2( char Num2) {
int Digit0 = Num2;
if(Digit0 > 47 && Digit0 < 58) { //this covers 0-9
Digit0 = Digit0 - 48;
}else if (Digit0 > 64 && Digit0 < 71) { // this covers A-F
Digit0 = Digit0 - 55;
}
Display(3 , Digit0);
}
void Display(int pos, int N) {
digitalWrite(9 ,LOW); // Apaga todos los digitos
digitalWrite(10,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);

for (int i= 0 ; i<8 ; i++)


digitalWrite(i+2 , Digit[N][i]) ;

digitalWrite(pos + 9, HIGH); // Enciende el digito pos


delay(8);

digitalWrite(9 ,LOW); // Vuelve a apagar todos los digitos


digitalWrite(10,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
}

You might also like