Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.89 KB | None | 0 0
  1. /*
  2. This is an example of the "Bank" class of the MIDI_controller library.
  3. Connect two potentiometers to analog pins A0 and A1,
  4. and two pushbuttons to pins 2 and 3.
  5.  
  6. Connect push buttons to pins 11 and 12, and 4 LEDs (+ current limiting resitors) to pins 4, 5, 6 and 7).
  7.  
  8. When bank 1 is selected:
  9. Potentiometer A is channel volume of track 1 (Controller number 0x07, MIDI channel 1)
  10. Potentiometer B is channel volume of track 2 (Controller number 0x07, MIDI channel 2)
  11. Mute button A is the mute button for track 1 (Note number 0x10, MIDI channel 1)
  12. Mute button B is the mute button for track 2 (Note number 0x11, MIDI channel 1)
  13. The LED on pin 4 lights up.
  14.  
  15. When bank 2 is selected:
  16. Potentiometer A is channel volume of track 3 (Controller number 0x07, MIDI channel 3)
  17. Potentiometer B is channel volume of track 4 (Controller number 0x07, MIDI channel 4)
  18. Mute button A is the mute button for track 3 (Note number 0x12, MIDI channel 1)
  19. Mute button B is the mute button for track 4 (Note number 0x13, MIDI channel 1)
  20. The LED on pin 5 lights up.
  21.  
  22. When bank 3 is selected:
  23. Potentiometer A is channel volume of track 5 (Controller number 0x07, MIDI channel 5)
  24. Potentiometer B is channel volume of track 6 (Controller number 0x07, MIDI channel 6)
  25. Mute button A is the mute button for track 5 (Note number 0x14, MIDI channel 1)
  26. Mute button B is the mute button for track 6 (Note number 0x15, MIDI channel 1)
  27. The LED on pin 6 lights up.
  28.  
  29. When bank 4 is selected:
  30. Potentiometer A is channel volume of track 7 (Controller number 0x07, MIDI channel 7)
  31. Potentiometer B is channel volume of track 8 (Controller number 0x07, MIDI channel 8)
  32. Mute button A is the mute button for track 7 (Note number 0x16, MIDI channel 1)
  33. Mute button B is the mute button for track 8 (Note number 0x17, MIDI channel 1)
  34. The LED on pin 7 lights up.
  35.  
  36. This allows you to control multiple tracks with only a limited amount of physical potentiometers and buttons
  37.  
  38. Map accordingly in your DAW or DJ software.
  39.  
  40. Written by Pieter P, 08-09-2017
  41. https://github.com/tttapa/MIDI_controller
  42. */
  43.  
  44. #include <MIDI_Controller.h> // Include the library
  45.  
  46. // Create a two new instances of the class 'Analog', on pins A0 and A1,
  47. // that send MIDI messages with controller 7 (channel volume) on channels 1 and 2
  48. Analog potentiometer_A(A0, MIDI_CC::Channel_Volume, 1);
  49. Analog potentiometer_B(A1, MIDI_CC::Channel_Volume, 2);
  50.  
  51. // Create a two new instances of the class 'Digital', on pins 2 and 3,
  52. // that send MIDI messages with note numbers 0x10 and 0x11 on MIDI channel 1
  53. Digital muteButton_A(2, 0x10, 1);
  54. Digital muteButton_B(3, 0x11, 1);
  55.  
  56. // Create a new bank that has two tracks per bank
  57. Bank bank(2);
  58.  
  59. // Create a new bank selector that changes the bank setting of the bank we just created
  60. // It has pushbuttons connected to pins 11 and 12 that increment or decrement the bank setting,
  61. // and 4 LEDs to pins 4, 5, 6 and 7 that display the current bank setting.
  62. BankSelector bankSelector(bank, { 11, 12 }, { 4, 5, 6, 7 } );
  63.  
  64. /* Alternatively, you can use arrays for the pin numbers:
  65.  
  66. const pin_t buttonPins[] = { 11, 12 };
  67. const pin_t ledPins[] = { 4, 5, 6, 7 };
  68.  
  69. BankSelector bankSelector(bank, buttonPins, ledPins);
  70. */
  71.  
  72. /*_______________________________________________________________________________________________________________________________________*/
  73.  
  74. void setup() {
  75. // Add the created objects to the bank
  76. bank.add(potentiometer_A, Bank::CHANGE_CHANNEL); // When the bank setting is changed, change the channel of the potentiometer
  77. bank.add(potentiometer_B, Bank::CHANGE_CHANNEL);
  78. bank.add(muteButton_A, Bank::CHANGE_ADDRESS); // When the bank setting is changed, change the address (note number) of the mute button
  79. bank.add(muteButton_B, Bank::CHANGE_ADDRESS);
  80. }
  81.  
  82. /*_______________________________________________________________________________________________________________________________________*/
  83.  
  84. void loop() {
  85. // Refresh the MIDI controller (check whether the inputs have changed since last time, if so, send the new value over MIDI)
  86. // It also refreshes the bank selector
  87. MIDI_Controller.refresh();
  88. }
  89.  
  90. /*
  91. Different Bank Select modes:
  92.  
  93. - One toggle switch (latching switch)
  94.  
  95. When the switch is in the 'off' position, bankSetting 1 is selected
  96. When the switch is in the 'on' position, bankSetting 2 is selected
  97.  
  98. BankSelector(bank, switch pin, BankSelector::TOGGLE);
  99.  
  100.  
  101. - One toggle switch (latching switch) and one LED
  102.  
  103. When the switch is in the 'off' position, bankSetting 1 is selected and the LED is off
  104. When the switch is in the 'on' position, bankSetting 2 is selected and the LED is on
  105.  
  106. Note: this mode is pretty useless, you can just connect the LED to the switch directly,
  107. without wasting a digital output pin on it.
  108.  
  109. BankSelector(bank, switch pin, led pin, BankSelector::TOGGLE);
  110.  
  111.  
  112. - One momentary switch (push button)
  113.  
  114. Pressing the button switches the bankSetting:
  115. When starting the program, bankSetting 1 is selected,
  116. When the button is pressed, bankSetting 2 is selected,
  117. When the button is pressed again, bankSetting 1 is selected,
  118. and so on.
  119.  
  120. BankSelector(bank, button pin);
  121. BankSelector(bank, button pin, BankSelector::MOMENTARY);
  122.  
  123.  
  124. - One momentary switch (push button) and one LED
  125.  
  126. Pressing the button switches the bankSetting and toggles the LED:
  127. When starting the program, bankSetting 1 is selected and the LED is off,
  128. When the button is pressed, bankSetting 2 is selected and the LED turns on,
  129. When the button is pressed again, bankSetting 1 is selected and the LED is turned off,
  130. and so on.
  131.  
  132. BankSelector(bank, button pin, led pin);
  133. BankSelector(bank, button pin, led pin, BankSelector::MOMENTARY);
  134.  
  135.  
  136. - Multiple momentary switches (push buttons)
  137.  
  138. Pressing one of the buttons selects the respective output:
  139. When starting the program, bankSetting 1 is selected,
  140. When the second button is pressed, bankSetting 2 is selected,
  141. When the n-th button is pressed, bankSetting n is selected.
  142.  
  143. BankSelector(bank, { button 1 pin, button 2 pin, ... , button n pin } );
  144.  
  145.  
  146. - Multiple momentary switches (push buttons) and multiple LEDs
  147.  
  148. Pressing one of the buttons selects the respective output and enables the respective LED:
  149. When starting the program, bankSetting 1 is selected and LED 1 is on,
  150. When the second button is pressed, bankSetting 2 is selected, LED 1 turns off and LED 2 turns on,
  151. When the n-th button is pressed, bankSetting n is selected, LED n turns on, and all other LEDs are off.
  152.  
  153. BankSelector(bank, { button 1 pin, button 2 pin, ... , button n pin }, { led 1 pin, led 2 pin, ... , led n pin } );
  154.  
  155.  
  156. - Two momentary switches (push buttons)
  157.  
  158. Pressing the first button increments the bankSetting number,
  159. pressing the second button decrements the bankSetting number:
  160. When starting the program, bankSetting 1 is selected,
  161. When the first button is pressed, bankSetting 2 is selected,
  162. When the first button is pressed again, bankSetting 3 is selected,
  163. When the last bankSetting is selected, and the first button is pressed again,
  164. bankSetting 1 is selected.
  165. When the second button is pressed, the last bankSetting (n) is selected,
  166. When the second button is pressed again, bankSetting (n-1) is selected,
  167. and so on.
  168.  
  169. BankSelector(bank, { button increment pin, button decrement pin }, number of bankSettings);
  170.  
  171.  
  172. - Two momentary switches (push buttons) and multiple LEDs
  173.  
  174. Pressing the first button increments the bankSetting number and turns on the respective LED,
  175. pressing the second button decrements the bankSetting number and turns on the respective LED:
  176. When starting the program, bankSetting 1 is selected and LED 1 is on,
  177. When the first button is pressed, bankSetting 2 is selected, LED 1 turns off and LED 2 turns on,
  178. When the first button is pressed again, bankSetting 3 is selected, LED 2 turns off and LED 3 turns on.
  179. When the last bankSetting is selected, and the first button is pressed,
  180. bankSetting 1 is selected, the last LED turns off and LED 1 turns on.
  181. When the second button is pressed, the last bankSetting (n) is selected, LED 1 turns off and LED n turns on,
  182. When the second button is pressed again, bankSetting (n-1) is selected, LED n turns off and LED n-1 turns on,
  183. and so on.
  184.  
  185. BankSelector(bank, { button increment pin, button decrement pin }, { led 1 pin, led 2 pin, ... , led n pin });
  186.  
  187.  
  188. - One momentary switch (push button)
  189.  
  190. Pressing the button increments the bankSetting number,
  191. When starting the program, bankSetting 1 is selected,
  192. When the button is pressed, bankSetting 2 is selected,
  193. When the button is pressed again, bankSetting 3 is selected,
  194. When the last bankSetting is selected, and the button is pressed again,
  195. bankSetting 1 is selected.
  196.  
  197. BankSelector(bank, { button increment pin }, number of bankSettings);
  198.  
  199.  
  200. - One momentary switch (push button) and multiple LEDs
  201.  
  202. Pressing the button increments the bankSetting number and turns on the respective LED,
  203. When starting the program, bankSetting 1 is selected and LED 1 is on,
  204. When the button is pressed, bankSetting 2 is selected, LED 1 turns off and LED 2 turns on,
  205. When the button is pressed again, bankSetting 3 is selected, LED 2 turns off and LED 3 turns on.
  206. When the last bankSetting is selected, and the button is pressed,
  207. bankSetting 1 is selected, the last LED turns off and LED 1 turns on.
  208.  
  209. BankSelector(bank, { button increment pin }, { led 1 pin, led 2 pin, ... , led n pin });
  210.  
  211.  
  212. Note: a switch is 'off' or 'released' when it doesn't conduct. The digital value
  213. on the input will therefore be HIGH (because of the pull-up resistor)
  214. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement