Advertisement
wystup

Untitled

Nov 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.75 KB | None | 0 0
  1. #include <Keypad.h>
  2.  
  3.  
  4.  
  5. int latchPin = 9;
  6. int clockPin = 8;
  7. int dataPin = 10;
  8. byte data = 0;
  9.  
  10. const byte ROWS = 4;
  11. const byte COLS = 2;
  12. char keys[ROWS][COLS] = {
  13. {'1','2'},
  14. {'3','4'},
  15. {'5','6'},
  16. {'7','8'}
  17. };
  18. byte rowPins[ROWS] = {7,6,5,4};
  19. byte colPins[COLS] = {3,2};
  20. Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,ROWS,COLS);
  21.  
  22.  
  23. 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.
  24. int lastVal = 0;
  25. int val2 = 0;
  26. int lastVal2 = 0;
  27. int val3 = 0;
  28. int lastVal3 = 0;
  29. 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.
  30. int lastVal4 = 0;
  31. int val5 = 0;
  32. int lastVal5 = 0;
  33. int val6 = 0;
  34. int lastVal6 = 0;
  35. int val7 = 0;
  36. int lastVal7 = 0;
  37. int val8 = 0;
  38. int lastVal8 = 0;
  39.  
  40. int page[8];
  41.  
  42. void setup()
  43. {
  44. pinMode(latchPin, OUTPUT);
  45. pinMode(clockPin, OUTPUT);
  46. pinMode(dataPin, OUTPUT);
  47.  
  48. Serial.begin(9600); // Set the speed of the midi port to the same as we will be using in the Hairless Midi software
  49. }
  50.  
  51. void loop()
  52. {
  53. char key = keypad.getKey();
  54.  
  55. if(key != NO_KEY){
  56.  
  57. switch(key){
  58.  
  59. case '1': // VCO 1/VCO 2
  60. lightShiftPinA(7);
  61. page[0] = 8;
  62. page[1] = 9;
  63. page[2] = 15;
  64. page[3] = 17;
  65. page[4] = 18;
  66. page[5] = 19;
  67. page[6] = 20;
  68. page[7] = 21;
  69.  
  70.  
  71. break;
  72.  
  73. case '2': // MIX/UNISON//VCA
  74. lightShiftPinA(3);
  75. page[0] = 23; // page2
  76. page[1] = 24;
  77. page[2] = 25;
  78. page[3] = 3;
  79. page[4] = 83;
  80. page[5] = 14;
  81. page[6] = 7;
  82. page[7] = 10;
  83.  
  84. break;
  85.  
  86. case '3': // FILTER
  87. lightShiftPinA(6);
  88. page[0] = 74;
  89. page[1] = 71;
  90. page[2] = 27;
  91. page[3] = 79;
  92. page[4] = 30;
  93. page[5] = 68;
  94. page[6] = 28;
  95. page[7] = 82;
  96.  
  97. break;
  98.  
  99. case '4': // // ADSR
  100. lightShiftPinA(2);
  101. page[0] = 85;
  102. page[1] = 86;
  103. page[2] = 87;
  104. page[3] = 88;
  105. page[4] = 73;
  106. page[5] = 75;
  107. page[6] = 70;
  108. page[7] = 72;
  109.  
  110. break;
  111.  
  112. case '5': // LFO
  113. lightShiftPinA(5);
  114. page[0] = 89;
  115. page[1] = 90;
  116. page[2] = 102;
  117. page[3] = 76;
  118. page[4] = 0;
  119. page[5] = 0;
  120. page[6] = 0;
  121. page[7] = 0;
  122.  
  123. break;
  124.  
  125. case '6':
  126. lightShiftPinA(1);
  127. page[0] = 41;
  128. page[1] = 42;
  129. page[2] = 43;
  130. page[3] = 44;
  131. page[4] = 45;
  132. page[5] = 46;
  133. page[6] = 47;
  134. page[7] = 48;
  135.  
  136. break;
  137.  
  138. case '7':
  139. lightShiftPinA(4); //
  140. page[0] = 49;
  141. page[1] = 50;
  142. page[2] = 51;
  143. page[3] = 52;
  144. page[4] = 53;
  145. page[5] = 54;
  146. page[6] = 55;
  147. page[7] = 56;
  148.  
  149. break;
  150.  
  151. case '8':
  152. lightShiftPinA(0);
  153. page[0] = 57;
  154. page[1] = 58;
  155. page[2] = 59;
  156. page[3] = 60;
  157. page[4] = 61;
  158. page[5] = 62;
  159. page[6] = 63;
  160. page[7] = 64;
  161.  
  162. break;
  163.  
  164. }
  165. }
  166.  
  167.  
  168. val = analogRead(0)/8; // Divide by 8 to get range of 0-127 for midi
  169. 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.
  170. {
  171. 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)
  172. lastVal = val;
  173.  
  174. val2 = analogRead(1)/8; // Divide by 8 to get range of 0-127 for midi
  175. if (val2 != lastVal2)
  176. {
  177. MIDImessage(176,page[1],val2);} // 176 = CC command, 2 = Which Control, val = value read from Potentionmeter 2
  178. lastVal2 = val2;
  179.  
  180. val3 = analogRead(2)/8; // Divide by 8 to get range of 0-127 for midi
  181. if (val3 != lastVal3)
  182. {
  183. MIDImessage(176,page[2],val3);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
  184. lastVal3 = val3;
  185.  
  186. val4 = analogRead(3)/8; // Divide by 8 to get range of 0-127 for midi
  187. if (val4 != lastVal4)
  188. {
  189. MIDImessage(176,page[3],val3);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
  190. lastVal4 = val4;
  191.  
  192. val5 = analogRead(4)/8; // Divide by 8 to get range of 0-127 for midi
  193. if (val5 != lastVal5)
  194. {
  195. MIDImessage(176,page[4],val5);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
  196. lastVal5 = val5;
  197.  
  198. val6 = analogRead(5)/8; // Divide by 8 to get range of 0-127 for midi
  199. if (val6 != lastVal6)
  200. {
  201. MIDImessage(176,page[5],val6);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
  202. lastVal6 = val6;
  203.  
  204. val7 = analogRead(6)/8; // Divide by 8 to get range of 0-127 for midi
  205. if (val7 != lastVal7)
  206. {
  207. MIDImessage(176,page[6],val7);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
  208. lastVal7 = val7;
  209.  
  210. val8 = analogRead(7)/8; // Divide by 8 to get range of 0-127 for midi
  211. if (val8 != lastVal8)
  212. {
  213. MIDImessage(176,page[7],val8);} // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
  214. lastVal8 = val8;
  215.  
  216. delay(10);
  217. 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.
  218. }
  219.  
  220.  
  221. void MIDImessage(byte command, byte data1, byte data2) //pass values out through standard Midi Command
  222. {
  223. Serial.write(command);
  224. Serial.write(data1);
  225. Serial.write(data2);
  226. }
  227.  
  228. void lightShiftPinA(int p) {
  229. //defines a local variable
  230. int pin;
  231.  
  232. pin = 1<< p;
  233.  
  234. digitalWrite(latchPin, LOW);
  235. shiftOut(dataPin, clockPin, MSBFIRST, pin);
  236. digitalWrite(latchPin, HIGH);
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement