Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <AnalogMuxDeMux.h>
- AnalogMux amux(11, 12, 13, A0); // Define Mux
- AnalogMux amux1(8, 9, 10, A1);
- AnalogMux amux2(5, 6, 7, A2);
- #define NO_PINS 8 // Define number of Mux pins
- int Deck1PitchfaderLED = 4;
- int StartUpLED = 3;
- int Deck2PitchfaderLED = 2;
- // Define variables for readings and last states MUX1
- int Deck2PBM = 0;
- int Deck2PBMState = 0;
- int Deck1Pause = 0;
- int Deck1PauseState = 0;
- int Deck1Pitchfader = 0;
- int Deck1PitchfaderState = 0;
- int Deck2PBP = 0;
- int Deck2PBPState = 0;
- int Deck1Volumefader = 0;
- int Deck1VolumefaderState = 0;
- int Deck1Filter= 0;
- int Deck1FilterState = 0;
- int Deck1EQLow = 0;
- int Deck1EQLowState = 0;
- int Deck1EQMid = 0;
- int Deck1EQMidState = 0;
- // Define variables for readings and last states MUX2
- int Deck1Play = 0;
- int Deck1PlayState = 0;
- int Deck1Cue = 0;
- int Deck1CueState = 0;
- int Deck2Pitchfader = 0;
- int Deck2PitchfaderState = 0;
- int Deck2Pause = 0;
- int Deck2PauseState= 0;
- int Deck2Volumefader = 0;
- int Deck2VolumefaderState = 0;
- int Deck2EQLow = 0;
- int Deck2EQLowState = 0;
- int Deck2EQMid = 0;
- int Deck2EQMidState = 0;
- int Deck1EQHigh = 0;
- int Deck1EQHighState = 0;
- // Define variables for readings and last states MUX3
- int Deck2Play = 0;
- int Deck2PlayState = 0;
- int Deck1PBM = 0;
- int Deck1PBMState = 0;
- int Deck2Filter = 0;
- int Deck2FilterState = 0;
- int Deck1PBP = 0;
- int Deck1PBPState = 0;
- int Deck2Cue = 0;
- int Deck2CueState = 0;
- int MasterVolumefader = 0;
- int MasterVolumefaderState = 0;
- int Deck2EQHigh = 0;
- int Deck2EQHighState = 0;
- int Crossfader = 0;
- int CrossfaderState = 0;
- // MIDI events
- byte CC=176;
- byte ON=144;
- byte OFF=128;
- // Controller numbers
- byte CN0=1;
- byte CN1=2;
- byte CN2=3;
- byte CN3=4;
- byte CN4=5;
- byte CN5=6;
- byte CN6=7;
- byte CN7=8;
- byte CN8=9;
- byte CN9=10;
- byte CN10=11;
- byte CN11=12;
- byte CN12=13;
- byte CN13=14;
- byte CN14=15;
- byte CN15=16;
- byte CN16=17;
- byte CN17=18;
- byte CN18=19;
- byte CN19=20;
- byte CN20=21;
- byte CN21=22;
- byte CN22=23;
- byte CN23=24;
- // Midi Status byte for buttons
- byte on=127;
- byte off=0;
- void setup()
- {
- pinMode (13, OUTPUT); // Selector pin1 Mux1
- pinMode (12, OUTPUT); // Selector pin2 Mux1
- pinMode (11, OUTPUT); // Selector pin3 Mux1
- pinMode (10, OUTPUT); // Selector pin1 Mux2
- pinMode (9, OUTPUT); // Selector pin2 Mux2
- pinMode (8, OUTPUT); // Selector pin3 Mux2
- pinMode (7, OUTPUT); // Selector pin1 Mux3
- pinMode (6, OUTPUT); // Selector pin2 Mux3
- pinMode (5, OUTPUT); // Selector pin3 Mux3
- pinMode (Deck1PitchfaderLED, OUTPUT);
- pinMode (StartUpLED, OUTPUT);
- pinMode (Deck2PitchfaderLED, OUTPUT);
- pinMode (A0, INPUT); // Mux Common OUTPUT
- pinMode (A1, INPUT);
- pinMode (A2, INPUT);
- //Start the Startup led blinking pattern
- digitalWrite (Deck1PitchfaderLED, HIGH);
- digitalWrite (Deck2PitchfaderLED, HIGH);
- delay(300);
- digitalWrite (Deck1PitchfaderLED, LOW);
- digitalWrite (Deck2PitchfaderLED, LOW);
- delay(300);
- digitalWrite (Deck1PitchfaderLED, HIGH);
- digitalWrite (Deck2PitchfaderLED, HIGH);
- for (int i=0; i<=255; i++)
- {
- delay(2);
- analogWrite(StartUpLED, i);
- }
- digitalWrite(StartUpLED, LOW);
- digitalWrite (Deck1PitchfaderLED, LOW);
- digitalWrite (Deck2PitchfaderLED, LOW);
- delay(300);
- digitalWrite (Deck1PitchfaderLED, HIGH);
- digitalWrite (Deck2PitchfaderLED, HIGH);
- digitalWrite (StartUpLED, HIGH);
- delay(1500);
- digitalWrite (Deck1PitchfaderLED, LOW);
- digitalWrite (Deck2PitchfaderLED, LOW);
- digitalWrite (StartUpLED, LOW);
- Serial.begin(31250);
- }
- void loop()
- {
- digitalWrite(StartUpLED, HIGH);
- // Read the values from the pots and buttons from MUX1
- int Deck2PBM = amux.AnalogRead (0) / 511;
- //delay(2);
- int Deck1Pause = amux.AnalogRead(1) / 511;
- //delay(2);
- int Deck1Pitchfader = amux.AnalogRead(2) / 8;
- //delay(2);
- int Deck2PBP = amux.AnalogRead(3) / 511;
- //delay(2);
- int Deck1Volumefader = amux.AnalogRead(4) / 8;
- //delay(2);
- int Deck1Filter = amux.AnalogRead(5) / 8;
- //delay(2);
- int Deck1EQLow = amux.AnalogRead(6) / 8;
- //delay(2);
- int Deck1EQMid = amux.AnalogRead(7) / 8;
- // Check to see if Mux1pin0 has changed values and send midi event - button on
- if (Deck2PBM != Deck2PBMState)
- {
- if (Deck2PBM == 2)
- {
- Serial.write(ON);
- Serial.write(CN0);
- Serial.write(on);
- }
- }
- // Check to see if button is released
- if (Deck2PBM == 0 && Deck2PBMState == 2)
- {
- Serial.write(OFF);
- Serial.write(CN0);
- Serial.write(off);
- }
- Deck2PBMState=Deck2PBM;
- // Check to see if Mux1pin1 has changed values
- if (Deck1Pause != Deck1PauseState)
- {
- if (Deck1Pause == 2)
- {
- Serial.write(ON);
- Serial.write(CN1);
- Serial.write(on);
- }
- }
- if (Deck1Pause == 0 && Deck1PauseState == 2)
- {
- Serial.write(OFF);
- Serial.write(CN1);
- Serial.write(off);
- }
- Deck1PauseState=Deck1Pause;
- // Check to see if Mux1pin2 has changed values
- if (abs(Deck1Pitchfader - Deck1PitchfaderState) >=2)
- {
- Serial.write(CC);
- Serial.write(CN2);
- Serial.write(Deck1Pitchfader);
- Deck1PitchfaderState = Deck1Pitchfader;
- }
- //If pitchfader is centered light LED
- if (Deck1Pitchfader == 64)
- {
- digitalWrite(Deck1PitchfaderLED, HIGH);
- }
- else
- {
- digitalWrite(Deck1PitchfaderLED,LOW);
- }
- // Check to see if Mux1pin3 has changed values
- if (Deck2PBP != Deck2PBPState)
- {
- if (Deck2PBP == 2)
- {
- Serial.write(ON);
- Serial.write(CN3);
- Serial.write(on);
- }
- }
- // Check to see if button is released
- if (Deck2PBP == 0 && Deck2PBPState == 2)
- {
- Serial.write(OFF);
- Serial.write(CN3);
- Serial.write(off);
- }
- Deck2PBPState=Deck2PBP;
- // Check to see if Mux1pin4 has changed its values
- if (abs(Deck1Volumefader - Deck1VolumefaderState) >= 2)
- {
- Serial.write(CC);
- Serial.write(CN4);
- Serial.write(Deck1Volumefader);
- Deck1VolumefaderState=Deck1Volumefader;
- }
- // Check to see if Mux1pin5 has changed its values
- if (abs(Deck1Filter - Deck1FilterState) >= 2)
- {
- Serial.write(CC);
- Serial.write(CN5);
- Serial.write(Deck1Filter);
- Deck1FilterState=Deck1Filter;
- }
- // Check to see if Mux1pin6 has changed its values
- if (abs(Deck1EQLow - Deck1EQLowState) >= 2)
- {
- Serial.write(CC);
- Serial.write(CN6);
- Serial.write(Deck1EQLow);
- Deck1EQLowState=Deck1EQLow;
- }
- // Check to see if Mux1pin7 has changed its values
- if (abs(Deck1EQMid - Deck1EQMidState) >= 2)
- {
- Serial.write(CC);
- Serial.write(CN7);
- Serial.write(Deck1EQMid);
- Deck1EQMidState=Deck1EQMid;
- }
- // END OF MUX1
- // Read the values from the pots and buttons from MUX2
- int Deck1Play = amux1.AnalogRead (0)/ 511;
- //delay(2);
- int Deck1Cue = amux1.AnalogRead(1)/511;
- //delay(2);
- int Deck2Pitchfader = amux1.AnalogRead(2) / 8;
- //delay(2);
- int Deck2Pause = amux1.AnalogRead(3)/511;
- //delay(2);
- int Deck2Volumefader = amux1.AnalogRead(4) / 8;
- //delay(2);
- int Deck2EQLow = amux1.AnalogRead(5) / 8;
- //delay(2);
- int Deck2EQMid = amux1.AnalogRead(6) / 8;
- //delay(2);
- int Deck1EQHigh = amux1.AnalogRead(7) / 8;
- // Check to see if Mux2pin0 has changed values and send midi event - button on
- if (Deck1Play != Deck1PlayState)
- {
- if (Deck1Play == 1)
- {
- Serial.write(ON);
- Serial.write(CN8);
- Serial.write(on);
- }
- }
- // Check to see if button is released
- if (Deck1Play == 0 && Deck1PlayState == 1)
- {
- Serial.write(OFF);
- Serial.write(CN8);
- Serial.write(off);
- }
- Deck1PlayState=Deck1Play;
- // Check to see if Mux2pin1 has changed values
- if (Deck1Cue != Deck1CueState)
- {
- if (Deck1Cue == 1)
- {
- Serial.write(ON);
- Serial.write(CN9);
- Serial.write(on);
- }
- }
- if (Deck1Cue == 0 && Deck1CueState == 1)
- {
- Serial.write(OFF);
- Serial.write(CN9);
- Serial.write(off);
- }
- Deck1CueState=Deck1Cue;
- // Check to see if Mux2pin2 has changed values
- if (abs(Deck2Pitchfader - Deck2PitchfaderState) >=2)
- {
- Serial.write(CC);
- Serial.write(CN10);
- Serial.write(Deck2Pitchfader);
- Deck2PitchfaderState = Deck2Pitchfader;
- }
- //If pitchfader2 is centered light up led
- if (Deck2Pitchfader == 64)
- {
- digitalWrite(Deck2PitchfaderLED, HIGH);
- }
- else
- {
- digitalWrite(Deck2PitchfaderLED,LOW);
- }
- // Check to see if Mux2pin3 has changed values
- if (Deck2Pause != Deck2PauseState)
- {
- if (Deck2Pause == 2)
- {
- Serial.write(ON);
- Serial.write(CN11);
- Serial.write(on);
- }
- }
- // Check to see if button is released
- if (Deck2Pause == 0 && Deck2PauseState == 2)
- {
- Serial.write(OFF);
- Serial.write(CN11);
- Serial.write(off);
- }
- Deck2PauseState=Deck2Pause;
- // Check to see if Mux2pin4 has changed its values
- if (abs(Deck2Volumefader - Deck2VolumefaderState) >= 2)
- {
- Serial.write(CC);
- Serial.write(CN12);
- Serial.write(Deck2Volumefader);
- Deck2VolumefaderState=Deck2Volumefader;
- }
- // Check to see if Mux2pin5 has changed its values
- if (abs(Deck2EQLow - Deck2EQLowState) >= 2)
- {
- Serial.write(CC);
- Serial.write(CN13);
- Serial.write(Deck2EQLow);
- Deck2EQLowState=Deck2EQLow;
- }
- // Check to see if Mux2pin6 has changed its values
- if (abs(Deck2EQMid - Deck2EQMidState) >= 2)
- {
- Serial.write(CC);
- Serial.write(CN14);
- Serial.write(Deck2EQMid);
- Deck2EQMidState=Deck2EQMid;
- }
- // Check to see if Mux2pin7 has changed its values
- if (abs(Deck1EQHigh - Deck1EQHighState) >= 2)
- {
- Serial.write(CC);
- Serial.write(CN15);
- Serial.write(Deck1EQHigh);
- Deck1EQHighState=Deck1EQHigh;
- }
- // END OF MUX2
- // Read the values from the pots and buttons from MUX3
- int Deck2Play = amux2.AnalogRead (0)/511;
- //delay(2);
- int Deck1PBM = amux2.AnalogRead(1)/511;
- //delay(2);
- int Deck2Cue = amux2.AnalogRead(2)/511;
- //delay(2);
- int Deck1PBP = amux2.AnalogRead(3)/511;
- //delay(2);
- int Deck2Filter = amux2.AnalogRead(4) / 8;
- //delay(2);
- int MasterVolumefader = amux2.AnalogRead(5) / 8;
- //delay(2);
- int Deck2EQHigh = amux2.AnalogRead(6) / 8;
- //delay(2);
- int Crossfader = amux2.AnalogRead(7) / 8;
- // Check to see if Mux3pin0 has changed values and send midi event - button on
- if (Deck2Play != Deck2PlayState)
- {
- if (Deck2Play == 1)
- {
- Serial.write(ON);
- Serial.write(CN16);
- Serial.write(on);
- }
- }
- // Check to see if button is released
- if (Deck2Play == 0 && Deck2PlayState == 1)
- {
- Serial.write(OFF);
- Serial.write(CN16);
- Serial.write(off);
- }
- Deck2PlayState=Deck2Play;
- // Check to see if Mux3pin1 has changed values
- if (Deck1PBM != Deck1PBMState)
- {
- if (Deck1PBM == 1)
- {
- Serial.write(ON);
- Serial.write(CN17);
- Serial.write(on);
- }
- }
- if (Deck1PBM == 0 && Deck1PBMState == 1)
- {
- Serial.write(OFF);
- Serial.write(CN17);
- Serial.write(off);
- }
- Deck1PBMState=Deck1PBM;
- // Check to see if Mux3pin2 has changed values
- if (Deck2Cue != Deck2CueState)
- {
- if (Deck2Cue == 1)
- {
- Serial.write(ON);
- Serial.write(CN18);
- Serial.write(on);
- }
- }
- if (Deck2Cue == 0 && Deck2CueState == 1)
- {
- Serial.write(OFF);
- Serial.write(CN18);
- Serial.write(off);
- }
- Deck2CueState=Deck2Cue;
- // Check to see if Mux3pin3 has changed values
- if (Deck1PBP != Deck1PBPState)
- {
- if (Deck1PBP == 1)
- {
- Serial.write(ON);
- Serial.write(CN19);
- Serial.write(on);
- }
- }
- // Check to see if button is released
- if (Deck1PBP == 0 && Deck1PBPState == 1)
- {
- Serial.write(OFF);
- Serial.write(CN19);
- Serial.write(off);
- }
- Deck1PBPState=Deck1PBP;
- // Check to see if Mux3pin4 has changed its values
- if (abs(Deck2Filter - Deck2FilterState) >= 2)
- {
- Serial.write(CC);
- Serial.write(CN20);
- Serial.write(Deck2Filter);
- Deck2FilterState=Deck2Filter;
- }
- // Check to see if Mux3pin5 has changed its values
- if (abs(MasterVolumefader - MasterVolumefaderState) >= 2)
- {
- Serial.write(CC);
- Serial.write(CN21);
- Serial.write(MasterVolumefader);
- MasterVolumefaderState=MasterVolumefader;
- }
- // Check to see if Mux3pin6 has changed its values
- if (abs(Deck2EQHigh - Deck2EQHighState) >= 2)
- {
- Serial.write(CC);
- Serial.write(CN22);
- Serial.write(Deck2EQHigh);
- Deck2EQHighState=Deck2EQHigh;
- }
- // Check to see if Mux3pin7 has changed its values
- if (abs(Crossfader - CrossfaderState) >= 2)
- {
- Serial.write(CC);
- Serial.write(CN23);
- Serial.write(Crossfader);
- CrossfaderState=Crossfader;
- }
- // END OF MUX3
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement