Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Keypad.h>
- int latchPin = 9;
- int clockPin = 8;
- int dataPin = 10;
- byte data = 0;
- const byte ROWS = 4;
- const byte COLS = 2;
- char keys[ROWS][COLS] = {
- {'1','2'},
- {'3','4'},
- {'5','6'},
- {'7','8'}
- };
- byte rowPins[ROWS] = {7,6,5,4};
- byte colPins[COLS] = {3,2};
- Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,ROWS,COLS);
- int val = 0; //Our initial pot values. We need one for the first value and a second to test if there has been a change made. This needs to be done for all 3 pots.
- int lastVal = 0;
- int val2 = 0;
- int lastVal2 = 0;
- int val3 = 0;
- int lastVal3 = 0;
- int val4 = 0; //Our initial pot values. We need one for the first value and a second to test if there has been a change made. This needs to be done for all 3 pots.
- int lastVal4 = 0;
- int val5 = 0;
- int lastVal5 = 0;
- int val6 = 0;
- int lastVal6 = 0;
- int val7 = 0;
- int lastVal7 = 0;
- int val8 = 0;
- int lastVal8 = 0;
- int page[8];
- void setup()
- {
- pinMode(latchPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- Serial.begin(9600); // Set the speed of the midi port to the same as we will be using in the Hairless Midi software
- }
- void loop()
- {
- char key = keypad.getKey();
- if(key != NO_KEY){
- switch(key){
- case '1': // VCO 1/VCO 2
- lightShiftPinA(7);
- page[0] = 8;
- page[1] = 9;
- page[2] = 15;
- page[3] = 17;
- page[4] = 18;
- page[5] = 19;
- page[6] = 20;
- page[7] = 21;
- break;
- case '2': // MIX/UNISON//VCA
- lightShiftPinA(3);
- page[0] = 23; // page2
- page[1] = 24;
- page[2] = 25;
- page[3] = 3;
- page[4] = 83;
- page[5] = 14;
- page[6] = 7;
- page[7] = 10;
- break;
- case '3': // FILTER
- lightShiftPinA(6);
- page[0] = 74;
- page[1] = 71;
- page[2] = 27;
- page[3] = 79;
- page[4] = 30;
- page[5] = 68;
- page[6] = 28;
- page[7] = 82;
- break;
- case '4': // // ADSR
- lightShiftPinA(2);
- page[0] = 85;
- page[1] = 86;
- page[2] = 87;
- page[3] = 88;
- page[4] = 73;
- page[5] = 75;
- page[6] = 70;
- page[7] = 72;
- break;
- case '5': // LFO
- lightShiftPinA(5);
- page[0] = 89;
- page[1] = 90;
- page[2] = 102;
- page[3] = 76;
- page[4] = 0;
- page[5] = 0;
- page[6] = 0;
- page[7] = 0;
- break;
- case '6':
- lightShiftPinA(1);
- page[0] = 41;
- page[1] = 42;
- page[2] = 43;
- page[3] = 44;
- page[4] = 45;
- page[5] = 46;
- page[6] = 47;
- page[7] = 48;
- break;
- case '7':
- lightShiftPinA(4); //
- page[0] = 49;
- page[1] = 50;
- page[2] = 51;
- page[3] = 52;
- page[4] = 53;
- page[5] = 54;
- page[6] = 55;
- page[7] = 56;
- break;
- case '8':
- lightShiftPinA(0);
- page[0] = 57;
- page[1] = 58;
- page[2] = 59;
- page[3] = 60;
- page[4] = 61;
- page[5] = 62;
- page[6] = 63;
- page[7] = 64;
- break;
- }
- }
- val = analogRead(0)/8; // Divide by 8 to get range of 0-127 for midi
- if (val != lastVal) // If the value does not = the last value the following command is made. This is because the pot has been turned. Otherwise the pot remains the same and no midi message is output.
- {
- MIDImessage(176,page[0],val);} // 176 = CC command (channel 1 control change), 1 = Which Control, val = value read from Potentionmeter 1 NOTE THIS SAYS VAL not VA1 (lowercase of course)
- lastVal = val;
- val2 = analogRead(1)/8; // Divide by 8 to get range of 0-127 for midi
- if (val2 != lastVal2)
- {
- MIDImessage(176,page[1],val2);} // 176 = CC command, 2 = Which Control, val = value read from Potentionmeter 2
- lastVal2 = val2;
- val3 = analogRead(2)/8; // Divide by 8 to get range of 0-127 for midi
- if (val3 != lastVal3)
- {
- MIDImessage(176,page[2],val3);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
- lastVal3 = val3;
- val4 = analogRead(3)/8; // Divide by 8 to get range of 0-127 for midi
- if (val4 != lastVal4)
- {
- MIDImessage(176,page[3],val3);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
- lastVal4 = val4;
- val5 = analogRead(4)/8; // Divide by 8 to get range of 0-127 for midi
- if (val5 != lastVal5)
- {
- MIDImessage(176,page[4],val5);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
- lastVal5 = val5;
- val6 = analogRead(5)/8; // Divide by 8 to get range of 0-127 for midi
- if (val6 != lastVal6)
- {
- MIDImessage(176,page[5],val6);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
- lastVal6 = val6;
- val7 = analogRead(6)/8; // Divide by 8 to get range of 0-127 for midi
- if (val7 != lastVal7)
- {
- MIDImessage(176,page[6],val7);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
- lastVal7 = val7;
- val8 = analogRead(7)/8; // Divide by 8 to get range of 0-127 for midi
- if (val8 != lastVal8)
- {
- MIDImessage(176,page[7],val8);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
- lastVal8 = val8;
- delay(10);
- delay(10); //here we add a short delay to help prevent slight fluctuations, knocks on the pots etc. Adding this helped to prevent my pots from jumpin up or down a value when slightly touched or knocked.
- }
- void MIDImessage(byte command, byte data1, byte data2) //pass values out through standard Midi Command
- {
- Serial.write(command);
- Serial.write(data1);
- Serial.write(data2);
- }
- void lightShiftPinA(int p) {
- //defines a local variable
- int pin;
- pin = 1<< p;
- digitalWrite(latchPin, LOW);
- shiftOut(dataPin, clockPin, MSBFIRST, pin);
- digitalWrite(latchPin, HIGH);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement