Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- // cc values for buttons
- int cc_off = 0;
- int cc_on = 65;
- int cc_super = 127;
- // map buttons to cc for button
- int cc0 = 32;
- int cc1 = 33;
- int cc2 = 34;
- int cc3 = 35;
- int cc4 = 36;
- int cc5 = 37;
- int cc6 = 38;
- int cc7 = 39;
- int cc8 = 40;
- int cc9 = 41;
- int cc10 = 42;
- int cc11 = 43;
- int cc12 = 44;
- int cc13 = 45;
- int cc14 = 46;
- int cc15 = 44;
- int cc16 = 44;
- int cc17 = 45;
- int cc18 = 46;
- int cc19 = 44;
- Bounce button0 = Bounce(0, 19);
- Bounce button1 = Bounce(1, 19);
- Bounce button2 = Bounce(2, 19);
- Bounce button3 = Bounce(3, 19);
- Bounce button4 = Bounce(4, 19);
- Bounce button5 = Bounce(5, 19);
- Bounce button6 = Bounce(6, 19);
- Bounce button7 = Bounce(7, 19);
- Bounce button8 = Bounce(8, 19);
- Bounce button9 = Bounce(9, 19);
- Bounce button10 = Bounce(10, 19);
- Bounce button11 = Bounce(11, 19);
- Bounce button12 = Bounce(12, 19);
- Bounce button13 = Bounce(13, 19);
- Bounce button14 = Bounce(14, 19);
- Bounce button15 = Bounce(15, 19);
- Bounce button16 = Bounce(16, 19);
- Bounce button17 = Bounce(17, 19);
- Bounce button18 = Bounce(18, 19);
- Bounce button19 = Bounce(19, 19);
- 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);
- pinMode(11, INPUT_PULLUP);
- }
- void loop() {
- // loop trough active inputs for knobs
- for (i=0;i<analogInputs;i++){
- // read current value at i-th input
- inputAnalog[i] = analogRead(i);
- // if magnitude of difference is 8 or more...
- if (abs(inputAnalog[i] - iAlag[i]) > 7){
- // calc the CC value based on the raw value
- ccValue[i] = inputAnalog[i]/8;
- // send the MIDI
- usbMIDI.sendControlChange(i, ccValue[i], 19);
- // set raw reading to lagged array for next comparison
- iAlag[i] = inputAnalog[i];
- }
- 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();
- button11.update();
- button12.update();
- button13.update();
- button14.update();
- button15.update();
- button16.update();
- button17.update();
- button18.update();
- button19.update();
- if (button0.fallingEdge())
- {
- usbMIDI.sendControlChange(cc0, cc_on, 19);
- }
- if (button1.fallingEdge())
- {
- usbMIDI.sendControlChange(cc1, cc_on, 19);
- }
- if (button2.fallingEdge())
- {
- usbMIDI.sendControlChange(cc2, cc_on, 19);
- }
- if (button3.fallingEdge())
- {
- usbMIDI.sendControlChange(cc3, cc_on, 19);
- }
- if (button4.fallingEdge())
- {
- usbMIDI.sendControlChange(cc4, cc_on, 19);
- }
- if (button5.fallingEdge())
- {
- usbMIDI.sendControlChange(cc5, cc_on, 19);
- }
- if (button6.fallingEdge())
- {
- usbMIDI.sendControlChange(cc6, cc_on, 19);
- }
- if (button7.fallingEdge())
- {
- usbMIDI.sendControlChange(cc7, cc_on, 19);
- }
- if (button8.fallingEdge())
- {
- usbMIDI.sendControlChange(cc8, cc_on, 19);
- }
- if (button9.fallingEdge())
- {
- usbMIDI.sendControlChange(cc9, cc_on, 19);
- }
- if (button10.fallingEdge())
- {
- usbMIDI.sendControlChange(cc10, cc_on, 19);
- }
- if (button11.fallingEdge())
- {
- usbMIDI.sendControlChange(cc11, cc_on, 19);
- }
- if (button12.fallingEdge())
- {
- usbMIDI.sendControlChange(cc12, cc_on, 19);
- }
- if (button13.fallingEdge())
- {
- usbMIDI.sendControlChange(cc13, cc_on, 19);
- }
- if (button14.fallingEdge())
- {
- usbMIDI.sendControlChange(cc14, cc_on, 19);
- }
- if (button15.fallingEdge())
- {
- usbMIDI.sendControlChange(cc15, cc_on, 19);
- }
- if (button16.fallingEdge())
- {
- usbMIDI.sendControlChange(cc16, cc_on, 19);
- }
- if (button17.fallingEdge())
- {
- usbMIDI.sendControlChange(cc17, cc_on, 19);
- }
- if (button18.fallingEdge())
- {
- usbMIDI.sendControlChange(cc18, cc_on, 19);
- }
- if (button19.fallingEdge())
- {
- usbMIDI.sendControlChange(cc19, cc_on, 19);
- }
- // begin rising edge!
- if (button0.risingEdge())
- {
- usbMIDI.sendControlChange(cc0, cc_off, 19);
- }
- if (button1.risingEdge())
- {
- usbMIDI.sendControlChange(cc1, cc_off, 19);
- }
- if (button2.risingEdge())
- {
- usbMIDI.sendControlChange(cc2, cc_off, 19);
- }
- if (button3.risingEdge())
- {
- usbMIDI.sendControlChange(cc3, cc_off, 19);
- }
- if (button4.risingEdge())
- {
- usbMIDI.sendControlChange(cc4, cc_off, 19);
- }
- if (button5.risingEdge())
- {
- usbMIDI.sendControlChange(cc5, cc_off, 19);
- }
- if (button6.risingEdge())
- {
- usbMIDI.sendControlChange(cc6, cc_off, 19);
- }
- if (button7.risingEdge())
- {
- usbMIDI.sendControlChange(cc7, cc_off, 19);
- }
- if (button8.risingEdge())
- {
- usbMIDI.sendControlChange(cc8, cc_off, 19);
- }
- if (button9.risingEdge())
- {
- usbMIDI.sendControlChange(cc9, cc_off, 19);
- }
- if (button10.risingEdge())
- {
- usbMIDI.sendControlChange(cc10, cc_off, 19);
- }
- if (button11.risingEdge())
- {
- usbMIDI.sendControlChange(cc11, cc_off, 19);
- }
- if (button12.risingEdge())
- {
- usbMIDI.sendControlChange(cc12, cc_off, 19);
- }
- if (button13.risingEdge())
- {
- usbMIDI.sendControlChange(cc13, cc_off, 19);
- }
- if (button14.risingEdge())
- {
- usbMIDI.sendControlChange(cc14, cc_off, 19);
- }
- if (button15.risingEdge())
- {
- usbMIDI.sendControlChange(cc15, cc_off, 19);
- }
- if (button16.risingEdge())
- {
- usbMIDI.sendControlChange(cc16, cc_off, 19);
- }
- if (button17.risingEdge())
- {
- usbMIDI.sendControlChange(cc17, cc_off, 19);
- }
- if (button18.risingEdge())
- {
- usbMIDI.sendControlChange(cc18, cc_off, 19);
- }
- if (button19.risingEdge())
- {
- usbMIDI.sendControlChange(cc19, cc_off, 19);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement