Advertisement
Guest User

Problema midi 9v

a guest
Mar 19th, 2021
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.18 KB | None | 0 0
  1.  
  2.  
  3. #include <MIDI.h>
  4. #include "Controller.h"
  5.  
  6. /*************************************************************
  7. MIDI CONTROLLER
  8.  
  9. by Notes and Volts
  10. www.notesandvolts.com
  11.  
  12. Version 1.2 **Arduino UNO ONLY!**
  13. *************************************************************/
  14.  
  15. MIDI_CREATE_DEFAULT_INSTANCE();
  16.  
  17. //************************************************************
  18. //***SET THE NUMBER OF CONTROLS USED**************************
  19. //************************************************************
  20. //---How many buttons are connected directly to pins?---------
  21. byte NUMBER_BUTTONS = 2;
  22. //---How many potentiometers are connected directly to pins?--
  23. byte NUMBER_POTS = 0;
  24. //---How many buttons are connected to a multiplexer?---------
  25. byte NUMBER_MUX_BUTTONS = 0;
  26. //---How many potentiometers are connected to a multiplexer?--
  27. byte NUMBER_MUX_POTS = 0;
  28. //************************************************************
  29.  
  30. //***ANY MULTIPLEXERS? (74HC4067)************************************
  31. //MUX address pins must be connected to Arduino UNO pins 2,3,4,5
  32. //A0 = PIN2, A1 = PIN3, A2 = PIN4, A3 = PIN5
  33. //*******************************************************************
  34. //Mux NAME (OUTPUT PIN, , How Many Mux Pins?(8 or 16) , Is It Analog?);
  35.  
  36.  
  37. //Mux M1(10, 16, false); //Digital multiplexer on Arduino pin 10
  38. //Mux M2(A5, 8, true); //Analog multiplexer on Arduino analog pin A0
  39. //*******************************************************************
  40.  
  41.  
  42. //***DEFINE DIRECTLY CONNECTED POTENTIOMETERS************************
  43. //Pot (Pin Number, Command, CC Control, Channel Number)
  44. //**Command parameter is for future use**
  45.  
  46. //Pot PO1(A0, 0, 1, 1);
  47. //Pot PO2(A1, 0, 10, 1);
  48. //Pot PO3(A2, 0, 22, 1);
  49. //Pot PO4(A3, 0, 118, 1);
  50. //Pot PO5(A4, 0, 30, 1);
  51. //Pot PO6(A5, 0, 31, 1);
  52. //*******************************************************************
  53. //Add pots used to array below like this-> Pot *POTS[] {&PO1, &PO2, &PO3, &PO4, &PO5, &PO6};
  54. Pot *POTS[] {};
  55. //*******************************************************************
  56.  
  57.  
  58. //***DEFINE DIRECTLY CONNECTED BUTTONS*******************************
  59. //Button (Pin Number, Command, Note Number, Channel, Debounce Time)
  60. //** Command parameter 0=NOTE 1=CC 2=Toggle CC **
  61.  
  62. Button BU1(9, 0, 60, 1, 5 );
  63. Button BU2(10, 0, 61, 1, 5 );
  64.  
  65. //*******************************************************************
  66. //Add buttons used to array below like this-> Button *BUTTONS[] {&BU1, &BU2, &BU3, &BU4, &BU5, &BU6, &BU7, &BU8};
  67. Button *BUTTONS[] {&BU1, &BU2,};
  68. //*******************************************************************
  69.  
  70.  
  71. //***DEFINE BUTTONS CONNECTED TO MULTIPLEXER*************************
  72. //Button::Button(Mux mux, byte muxpin, byte command, byte value, byte channel, byte debounce)
  73. //** Command parameter 0=NOTE 1=CC 2=Toggle CC **
  74.  
  75. //Button MBU1(M1, 0, 0, 70, 1, 5);
  76. //Button MBU2(M1, 1, 1, 71, 1, 5);
  77. //Button MBU3(M1, 2, 2, 72, 1, 5);
  78. //Button MBU4(M1, 3, 0, 73, 1, 5);
  79. //Button MBU5(M1, 4, 0, 74, 1, 5);
  80. //Button MBU6(M1, 5, 0, 75, 1, 5);
  81. //Button MBU7(M1, 6, 0, 76, 1, 5);
  82. //Button MBU8(M1, 7, 0, 77, 1, 5);
  83. //Button MBU9(M1, 8, 0, 78, 1, 5);
  84. //Button MBU10(M1, 9, 0, 79, 1, 5);
  85. //Button MBU11(M1, 10, 0, 80, 1, 5);
  86. //Button MBU12(M1, 11, 0, 81, 1, 5);
  87. //Button MBU13(M1, 12, 0, 82, 1, 5);
  88. //Button MBU14(M1, 13, 0, 83, 1, 5);
  89. //Button MBU15(M1, 14, 0, 84, 1, 5);
  90. //Button MBU16(M1, 15, 0, 85, 1, 5);
  91. //*******************************************************************
  92. ////Add multiplexed buttons used to array below like this-> Button *MUXBUTTONS[] {&MBU1, &MBU2, &MBU3, &MBU4, &MBU5, &MBU6.....};
  93. Button *MUXBUTTONS[] {};
  94.  
  95. //*******************************************************************
  96.  
  97.  
  98. //***DEFINE POTENTIOMETERS CONNECTED TO MULTIPLEXER*******************
  99. //Pot::Pot(Mux mux, byte muxpin, byte command, byte control, byte channel)
  100. //**Command parameter is for future use**
  101.  
  102. //Pot MPO1(M2, 0, 0, 1, 1);
  103. //Pot MPO2(M2, 1, 0, 7, 1);
  104. //Pot MPO3(M2, 2, 0, 50, 1);
  105. //Pot MPO4(M2, 3, 0, 55, 2);
  106. //Pot MPO5(M2, 4, 0, 50, 1);
  107. //Pot MPO6(M2, 5, 0, 55, 2);
  108. //Pot MPO7(M2, 6, 0, 50, 1);
  109. //Pot MPO8(M2, 7, 0, 55, 2);
  110. //Pot MPO9(M2, 8, 0, 50, 1);
  111. //Pot MPO10(M2, 9, 0, 55, 2);
  112. //Pot MPO11(M2, 10, 0, 50, 1);
  113. //Pot MPO12(M2, 11, 0, 55, 2);
  114. //Pot MPO13(M2, 12, 0, 50, 1);
  115. //Pot MPO14(M2, 13, 0, 55, 2);
  116. //Pot MPO15(M2, 14, 0, 50, 1);
  117. //Pot MPO16(M2, 15, 0, 55, 2);
  118. //*******************************************************************
  119. //Add multiplexed pots used to array below like this-> Pot *MUXPOTS[] {&MPO1, &MPO2, &MPO3, &MPO4, &MPO5, &MPO6.....};
  120. Pot *MUXPOTS[] {};
  121. //*******************************************************************
  122.  
  123.  
  124.  
  125. void setup() {
  126. MIDI.begin(MIDI_CHANNEL_OFF);
  127.  
  128. }
  129.  
  130. void loop() {
  131. if (NUMBER_BUTTONS != 0) updateButtons();
  132. if (NUMBER_POTS != 0) updatePots();
  133. if (NUMBER_MUX_BUTTONS != 0) updateMuxButtons();
  134. if (NUMBER_MUX_POTS != 0) updateMuxPots();
  135.  
  136.  
  137.  
  138. }
  139.  
  140.  
  141. //*****************************************************************
  142. void updateButtons() {
  143.  
  144. // Cycle through Button array
  145. for (int i = 0; i < NUMBER_BUTTONS; i = i + 1) {
  146. byte message = BUTTONS[i]->getValue();
  147.  
  148. // Button is pressed
  149. if (message == 0) {
  150. switch (BUTTONS[i]->Bcommand) {
  151. case 0: //Note
  152. MIDI.sendNoteOn(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
  153. break;
  154. case 1: //CC
  155. MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
  156. break;
  157. case 2: //Toggle
  158. if (BUTTONS[i]->Btoggle == 0) {
  159. MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
  160. BUTTONS[i]->Btoggle = 1;
  161. }
  162. else if (BUTTONS[i]->Btoggle == 1) {
  163. MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
  164. BUTTONS[i]->Btoggle = 0;
  165. }
  166. break;
  167. }
  168. }
  169.  
  170. // Button is not pressed
  171. if (message == 1) {
  172. switch (BUTTONS[i]->Bcommand) {
  173. case 0:
  174. MIDI.sendNoteOff(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
  175. break;
  176. case 1:
  177. MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
  178. break;
  179. }
  180. }
  181. }
  182. }
  183. //*******************************************************************
  184. void updateMuxButtons() {
  185.  
  186. // Cycle through Mux Button array
  187. for (int i = 0; i < NUMBER_MUX_BUTTONS; i = i + 1) {
  188.  
  189. MUXBUTTONS[i]->muxUpdate();
  190. byte message = MUXBUTTONS[i]->getValue();
  191.  
  192. // Button is pressed
  193. if (message == 0) {
  194. switch (MUXBUTTONS[i]->Bcommand) {
  195. case 0: //Note
  196. MIDI.sendNoteOn(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
  197. break;
  198. case 1: //CC
  199. MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
  200. break;
  201. case 2: //Toggle
  202. if (MUXBUTTONS[i]->Btoggle == 0) {
  203. MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
  204. MUXBUTTONS[i]->Btoggle = 1;
  205. }
  206. else if (MUXBUTTONS[i]->Btoggle == 1) {
  207. MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
  208. MUXBUTTONS[i]->Btoggle = 0;
  209. }
  210. break;
  211. }
  212. }
  213. // Button is not pressed
  214. if (message == 1) {
  215. switch (MUXBUTTONS[i]->Bcommand) {
  216. case 0:
  217. MIDI.sendNoteOff(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
  218. break;
  219. case 1:
  220. MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
  221. break;
  222. }
  223. }
  224. }
  225. }
  226. //***********************************************************************
  227. void updatePots() {
  228. for (int i = 0; i < NUMBER_POTS; i = i + 1) {
  229. byte potmessage = POTS[i]->getValue();
  230. if (potmessage != 255) MIDI.sendControlChange(POTS[i]->Pcontrol, potmessage, POTS[i]->Pchannel);
  231. }
  232. }
  233. //***********************************************************************
  234. void updateMuxPots() {
  235. for (int i = 0; i < NUMBER_MUX_POTS; i = i + 1) {
  236. MUXPOTS[i]->muxUpdate();
  237. byte potmessage = MUXPOTS[i]->getValue();
  238. if (potmessage != 255) MIDI.sendControlChange(MUXPOTS[i]->Pcontrol, potmessage, MUXPOTS[i]->Pchannel);
  239. }
  240. }
  241.  
  242.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement