Advertisement
Guest User

teensy code

a guest
Sep 10th, 2016
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.38 KB | None | 0 0
  1. #include <Bounce.h>
  2.  
  3. // define how many pots are active up to number of available analog inputs
  4. #define analogInputs 8
  5. // make arrays for input values and lagged input values
  6. int inputAnalog[analogInputs];
  7. int iAlag[analogInputs];
  8. // make array of cc values
  9. int ccValue[analogInputs];
  10. // index variable for loop
  11. int i;
  12.  
  13. // cc values for buttons
  14. int cc_off = 0;
  15. int cc_on = 65;
  16. int cc_super = 127;
  17.  
  18. // map buttons to cc for button
  19. int cc0 = 32;
  20. int cc1 = 33;
  21. int cc2 = 34;
  22. int cc3 = 35;
  23. int cc4 = 36;
  24. int cc5 = 37;
  25. int cc6 = 38;
  26. int cc7 = 39;
  27. int cc8 = 40;
  28. int cc9 = 41;
  29. int cc10 = 42;
  30. int cc11 = 43;
  31. int cc12 = 44;
  32. int cc13 = 45;
  33. int cc14 = 46;
  34. int cc15 = 44;
  35. int cc16 = 44;
  36. int cc17 = 45;
  37. int cc18 = 46;
  38. int cc19 = 44;
  39.  
  40.  
  41. Bounce button0 = Bounce(0, 19);
  42. Bounce button1 = Bounce(1, 19);
  43. Bounce button2 = Bounce(2, 19);
  44. Bounce button3 = Bounce(3, 19);
  45. Bounce button4 = Bounce(4, 19);
  46. Bounce button5 = Bounce(5, 19);
  47. Bounce button6 = Bounce(6, 19);
  48. Bounce button7 = Bounce(7, 19);
  49. Bounce button8 = Bounce(8, 19);
  50. Bounce button9 = Bounce(9, 19);
  51. Bounce button10 = Bounce(10, 19);
  52. Bounce button11 = Bounce(11, 19);
  53. Bounce button12 = Bounce(12, 19);
  54. Bounce button13 = Bounce(13, 19);
  55. Bounce button14 = Bounce(14, 19);
  56. Bounce button15 = Bounce(15, 19);
  57. Bounce button16 = Bounce(16, 19);
  58. Bounce button17 = Bounce(17, 19);
  59. Bounce button18 = Bounce(18, 19);
  60. Bounce button19 = Bounce(19, 19);
  61.  
  62.  
  63.  
  64.  
  65. void setup() {
  66.   // MIDI rate
  67.   Serial.begin(31250);
  68.   pinMode(0, INPUT_PULLUP);
  69.   pinMode(1, INPUT_PULLUP);
  70.   pinMode(2, INPUT_PULLUP);
  71.   pinMode(3, INPUT_PULLUP);
  72.   pinMode(4, INPUT_PULLUP);
  73.   pinMode(5, INPUT_PULLUP);
  74.   pinMode(6, INPUT_PULLUP);
  75.   pinMode(7, INPUT_PULLUP);
  76.   pinMode(8, INPUT_PULLUP);
  77.   pinMode(9, INPUT_PULLUP);
  78.   pinMode(10, INPUT_PULLUP);
  79.   pinMode(11, INPUT_PULLUP);
  80. }
  81.  
  82. void loop() {
  83.   // loop trough active inputs for knobs
  84.   for (i=0;i<analogInputs;i++){
  85.     // read current value at i-th input
  86.     inputAnalog[i] = analogRead(i);
  87.     // if magnitude of difference is 8 or more...
  88.     if (abs(inputAnalog[i] - iAlag[i]) > 7){
  89.       // calc the CC value based on the raw value
  90.       ccValue[i] = inputAnalog[i]/8;
  91.       // send the MIDI
  92.       usbMIDI.sendControlChange(i, ccValue[i], 19);
  93.       // set raw reading to lagged array for next comparison
  94.       iAlag[i] = inputAnalog[i];
  95.     }
  96.   delay(5); // limits MIDI messages to reasonable number
  97.   }
  98.  
  99.   // Push Button code
  100.   button0.update();
  101.   button1.update();
  102.   button2.update();
  103.   button3.update();
  104.   button4.update();
  105.   button5.update();
  106.   button6.update();
  107.   button7.update();
  108.   button8.update();
  109.   button9.update();
  110.   button10.update();
  111.   button11.update();
  112.   button12.update();
  113.   button13.update();
  114.   button14.update();
  115.   button15.update();
  116.   button16.update();
  117.   button17.update();
  118.   button18.update();
  119.   button19.update();
  120.  
  121.  
  122.  
  123.  
  124.  
  125.   if (button0.fallingEdge())
  126.   {
  127.     usbMIDI.sendControlChange(cc0, cc_on, 19);
  128.   }
  129.   if (button1.fallingEdge())
  130.   {
  131.     usbMIDI.sendControlChange(cc1, cc_on, 19);
  132.   }
  133.   if (button2.fallingEdge())
  134.   {
  135.     usbMIDI.sendControlChange(cc2, cc_on, 19);
  136.   }
  137.   if (button3.fallingEdge())
  138.   {
  139.     usbMIDI.sendControlChange(cc3, cc_on, 19);
  140.   }
  141.   if (button4.fallingEdge())
  142.   {
  143.     usbMIDI.sendControlChange(cc4, cc_on, 19);
  144.   }
  145.   if (button5.fallingEdge())
  146.   {
  147.     usbMIDI.sendControlChange(cc5, cc_on, 19);
  148.   }
  149.   if (button6.fallingEdge())
  150.   {
  151.     usbMIDI.sendControlChange(cc6, cc_on, 19);
  152.   }
  153.   if (button7.fallingEdge())
  154.   {
  155.     usbMIDI.sendControlChange(cc7, cc_on, 19);
  156.   }
  157.   if (button8.fallingEdge())
  158.   {
  159.     usbMIDI.sendControlChange(cc8, cc_on, 19);
  160.   }
  161.   if (button9.fallingEdge())
  162.   {
  163.     usbMIDI.sendControlChange(cc9, cc_on, 19);
  164.   }
  165.   if (button10.fallingEdge())
  166.   {
  167.     usbMIDI.sendControlChange(cc10, cc_on, 19);
  168.   }
  169.   if (button11.fallingEdge())
  170.   {
  171.     usbMIDI.sendControlChange(cc11, cc_on, 19);
  172.   }
  173.      if (button12.fallingEdge())
  174.   {
  175.     usbMIDI.sendControlChange(cc12, cc_on, 19);
  176.   }
  177.   if (button13.fallingEdge())
  178.   {
  179.     usbMIDI.sendControlChange(cc13, cc_on, 19);
  180.   }
  181.   if (button14.fallingEdge())
  182.   {
  183.     usbMIDI.sendControlChange(cc14, cc_on, 19);
  184.   }
  185.   if (button15.fallingEdge())
  186.   {
  187.     usbMIDI.sendControlChange(cc15, cc_on, 19);
  188.   }
  189.   if (button16.fallingEdge())
  190.   {
  191.     usbMIDI.sendControlChange(cc16, cc_on, 19);
  192.   }
  193.   if (button17.fallingEdge())
  194.   {
  195.     usbMIDI.sendControlChange(cc17, cc_on, 19);
  196.   }
  197.   if (button18.fallingEdge())
  198.   {
  199.     usbMIDI.sendControlChange(cc18, cc_on, 19);
  200.   }
  201.   if (button19.fallingEdge())
  202.   {
  203.     usbMIDI.sendControlChange(cc19, cc_on, 19);
  204.   }
  205.  
  206.  
  207.  
  208. // begin rising edge!
  209.  
  210.    
  211.   if (button0.risingEdge())
  212.   {
  213.     usbMIDI.sendControlChange(cc0, cc_off, 19);
  214.   }
  215.   if (button1.risingEdge())
  216.   {
  217.     usbMIDI.sendControlChange(cc1, cc_off, 19);
  218.   }
  219.   if (button2.risingEdge())
  220.   {
  221.     usbMIDI.sendControlChange(cc2, cc_off, 19);
  222.   }
  223.   if (button3.risingEdge())
  224.   {
  225.     usbMIDI.sendControlChange(cc3, cc_off, 19);
  226.   }
  227.   if (button4.risingEdge())
  228.   {
  229.     usbMIDI.sendControlChange(cc4, cc_off, 19);
  230.   }
  231.   if (button5.risingEdge())
  232.   {
  233.     usbMIDI.sendControlChange(cc5, cc_off, 19);
  234.   }
  235.   if (button6.risingEdge())
  236.   {
  237.     usbMIDI.sendControlChange(cc6, cc_off, 19);
  238.   }
  239.   if (button7.risingEdge())
  240.   {
  241.     usbMIDI.sendControlChange(cc7, cc_off, 19);
  242.   }
  243.   if (button8.risingEdge())
  244.   {
  245.     usbMIDI.sendControlChange(cc8, cc_off, 19);
  246.   }
  247.   if (button9.risingEdge())
  248.   {
  249.     usbMIDI.sendControlChange(cc9, cc_off, 19);
  250.   }
  251.   if (button10.risingEdge())
  252.   {
  253.     usbMIDI.sendControlChange(cc10, cc_off, 19);
  254.   }
  255.   if (button11.risingEdge())
  256.   {
  257.     usbMIDI.sendControlChange(cc11, cc_off, 19);
  258.   }
  259.   if (button12.risingEdge())
  260.   {
  261.     usbMIDI.sendControlChange(cc12, cc_off, 19);
  262.   }
  263.   if (button13.risingEdge())
  264.   {
  265.     usbMIDI.sendControlChange(cc13, cc_off, 19);
  266.   }
  267.   if (button14.risingEdge())
  268.   {
  269.     usbMIDI.sendControlChange(cc14, cc_off, 19);
  270.   }
  271.   if (button15.risingEdge())
  272.   {
  273.     usbMIDI.sendControlChange(cc15, cc_off, 19);
  274.   }
  275.   if (button16.risingEdge())
  276.   {
  277.     usbMIDI.sendControlChange(cc16, cc_off, 19);
  278.   }
  279.   if (button17.risingEdge())
  280.   {
  281.     usbMIDI.sendControlChange(cc17, cc_off, 19);
  282.   }
  283.   if (button18.risingEdge())
  284.   {
  285.     usbMIDI.sendControlChange(cc18, cc_off, 19);
  286.   }
  287.   if (button19.risingEdge())
  288.   {
  289.     usbMIDI.sendControlChange(cc19, cc_off, 19);
  290.   }
  291.  
  292. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement