Advertisement
Guest User

MymidicontrollerDEBUG

a guest
Oct 17th, 2012
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.32 KB | None | 0 0
  1. #include <AnalogMuxDeMux.h>
  2. AnalogMux amux(11, 12, 13, A0); // Define Mux
  3. AnalogMux amux1(8, 9, 10, A1);
  4. AnalogMux amux2(5, 6, 7, A2);
  5. #define NO_PINS 8 // Define number of Mux pins
  6. int Deck1PitchfaderLED = 4;
  7. int StartUpLED = 3;
  8. int Deck2PitchfaderLED = 2;
  9. // Define variables for readings and last states MUX1
  10. int Deck2PBM = 0;
  11. int Deck2PBMState = 0;
  12. int Deck1Pause = 0;
  13. int Deck1PauseState = 0;
  14. int Deck1Pitchfader = 0;
  15. int Deck1PitchfaderState = 0;
  16. int Deck2PBP = 0;
  17. int Deck2PBPState = 0;
  18. int Deck1Volumefader = 0;
  19. int Deck1VolumefaderState = 0;
  20. int Deck1Filter= 0;
  21. int Deck1FilterState = 0;
  22. int Deck1EQLow = 0;
  23. int Deck1EQLowState = 0;
  24. int Deck1EQMid = 0;
  25. int Deck1EQMidState = 0;
  26. // Define variables for readings and last states MUX2
  27. int Deck1Play = 0;
  28. int Deck1PlayState = 0;
  29. int Deck1Cue = 0;
  30. int Deck1CueState = 0;
  31. int Deck2Pitchfader = 0;
  32. int Deck2PitchfaderState = 0;
  33. int Deck2Pause = 0;
  34. int Deck2PauseState= 0;
  35. int Deck2Volumefader = 0;
  36. int Deck2VolumefaderState = 0;
  37. int Deck2EQLow = 0;
  38. int Deck2EQLowState = 0;
  39. int Deck2EQMid = 0;
  40. int Deck2EQMidState = 0;
  41. int Deck1EQHigh = 0;
  42. int Deck1EQHighState = 0;
  43. // Define variables for readings and last states MUX3
  44. int Deck2Play = 0;
  45. int Deck2PlayState = 0;
  46. int Deck1PBM = 0;
  47. int Deck1PBMState = 0;
  48. int Deck2Filter = 0;
  49. int Deck2FilterState = 0;
  50. int Deck1PBP = 0;
  51. int Deck1PBPState = 0;
  52. int Deck2Cue = 0;
  53. int Deck2CueState = 0;
  54. int MasterVolumefader = 0;
  55. int MasterVolumefaderState = 0;
  56. int Deck2EQHigh = 0;
  57. int Deck2EQHighState = 0;
  58. int Crossfader = 0;
  59. int CrossfaderState = 0;
  60. // MIDI events
  61.  
  62. // Controller numbers
  63.  
  64. // Midi Status byte for buttons
  65.  
  66. void setup()
  67. {
  68. pinMode (13, OUTPUT); // Selector pin1 Mux1
  69. pinMode (12, OUTPUT); // Selector pin2 Mux1
  70. pinMode (11, OUTPUT); // Selector pin3 Mux1
  71. pinMode (10, OUTPUT); // Selector pin1 Mux2
  72. pinMode (9, OUTPUT); // Selector pin2 Mux2
  73. pinMode (8, OUTPUT); // Selector pin3 Mux2
  74. pinMode (7, OUTPUT); // Selector pin1 Mux3
  75. pinMode (6, OUTPUT); // Selector pin2 Mux3
  76. pinMode (5, OUTPUT); // Selector pin3 Mux3
  77. pinMode (Deck1PitchfaderLED, OUTPUT);
  78. pinMode (StartUpLED, OUTPUT);
  79. pinMode (Deck2PitchfaderLED, OUTPUT);
  80. pinMode (A0, INPUT); // Mux Common OUTPUT
  81. pinMode (A1, INPUT);
  82. pinMode (A2, INPUT);
  83.  
  84. Serial.begin(115200);
  85. }
  86.  
  87. void loop()
  88. {
  89. digitalWrite(StartUpLED, HIGH);
  90.  
  91. // Read the values from the pots and buttons from MUX1
  92. int Deck2PBM = amux.AnalogRead (0) / 511;
  93. //delay(2);
  94. int Deck1Pause = amux.AnalogRead(1) / 511;
  95. //delay(2);
  96. int Deck1Pitchfader = amux.AnalogRead(2) / 8;
  97. //delay(2);
  98. int Deck2PBP = amux.AnalogRead(3) / 511;
  99. //delay(2);
  100. int Deck1Volumefader = amux.AnalogRead(4) / 8;
  101. //delay(2);
  102. int Deck1Filter = amux.AnalogRead(5) / 8;
  103. //delay(2);
  104. int Deck1EQLow = amux.AnalogRead(6) / 8;
  105. //delay(2);
  106. int Deck1EQMid = amux.AnalogRead(7) / 8;
  107.  
  108. // Check to see if Mux1pin0 has changed values and send midi event - button on
  109.  
  110. if (Deck2PBM != Deck2PBMState)
  111. {
  112. if (Deck2PBM == 2)
  113. {
  114. Serial.println("Deck2PBM");
  115. Serial.println("on");
  116. }
  117. }
  118.  
  119. // Check to see if button is released
  120.  
  121. if (Deck2PBM == 0 && Deck2PBMState == 2)
  122. {
  123. Serial.println("Deck2PBM");
  124. Serial.println("off");
  125. }
  126. Deck2PBMState=Deck2PBM;
  127.  
  128. // Check to see if Mux1pin1 has changed values
  129.  
  130. if (Deck1Pause != Deck1PauseState)
  131. {
  132. if (Deck1Pause == 2)
  133. {
  134. Serial.println("Deck1Pause");
  135. Serial.println("on");
  136. }
  137. }
  138.  
  139. if (Deck1Pause == 0 && Deck1PauseState == 2)
  140. {
  141. Serial.println("Deck1Pause");
  142. Serial.println("off");
  143. }
  144. Deck1PauseState=Deck1Pause;
  145.  
  146. // Check to see if Mux1pin2 has changed values
  147.  
  148.  
  149. if (abs(Deck1Pitchfader - Deck1PitchfaderState) >=2)
  150. {
  151. Serial.println("Deck1Pitchfader");
  152. Serial.println(Deck1Pitchfader);
  153. Deck1PitchfaderState = Deck1Pitchfader;
  154. }
  155.  
  156. if (Deck1Pitchfader == 64)
  157. {
  158. digitalWrite(Deck1PitchfaderLED, HIGH);
  159. }
  160. else
  161. {
  162. digitalWrite(Deck1PitchfaderLED,LOW);
  163. }
  164. // Check to see if Mux1pin3 has changed values
  165.  
  166. if (Deck2PBP != Deck2PBPState)
  167. {
  168. if (Deck2PBP == 2)
  169. {
  170. Serial.println("Deck2PBP");
  171. Serial.println("on");
  172. }
  173. }
  174.  
  175. // Check to see if button is released
  176.  
  177. if (Deck2PBP == 0 && Deck2PBPState == 2)
  178. {
  179. Serial.println("Deck2PBP");
  180. Serial.println("off");
  181. }
  182. Deck2PBPState=Deck2PBP;
  183.  
  184. // Check to see if Mux1pin4 has changed its values
  185.  
  186. if (abs(Deck1Volumefader - Deck1VolumefaderState) >= 2)
  187. {
  188. Serial.println("Deck1Volumefader");
  189. Serial.println(Deck1Volumefader);
  190. Deck1VolumefaderState=Deck1Volumefader;
  191. }
  192.  
  193. // Check to see if Mux1pin5 has changed its values
  194.  
  195. if (abs(Deck1Filter - Deck1FilterState) >= 2)
  196. {
  197. Serial.println("Deck1Filter");
  198. Serial.println(Deck1Filter);
  199. Deck1FilterState=Deck1Filter;
  200. }
  201.  
  202. // Check to see if Mux1pin6 has changed its values
  203.  
  204. if (abs(Deck1EQLow - Deck1EQLowState) >= 2)
  205. {
  206. Serial.println("Deck1EQLow");
  207. Serial.println(Deck1EQLow);
  208. Deck1EQLowState=Deck1EQLow;
  209. }
  210.  
  211. // Check to see if Mux1pin7 has changed its values
  212.  
  213. if (abs(Deck1EQMid - Deck1EQMidState) >= 2)
  214. {
  215. Serial.println("Deck1EQMid");
  216. Serial.println(Deck1EQMid);
  217. Deck1EQMidState=Deck1EQMid;
  218. }
  219. // END OF MUX1
  220.  
  221. // Read the values from the pots and buttons from MUX2
  222. int Deck1Play = amux1.AnalogRead (0) / 511;
  223. //delay(2);
  224. int Deck1Cue = amux1.AnalogRead(1) / 511;
  225. //delay(2);
  226. int Deck2Pitchfader = amux1.AnalogRead(2) / 8;
  227. //delay(2);
  228. int Deck2Pause = amux1.AnalogRead(3) / 511;
  229. //delay(2);
  230. int Deck2Volumefader = amux1.AnalogRead(4) / 8;
  231. //delay(2);
  232. int Deck2EQLow = amux1.AnalogRead(5) / 8;
  233. //delay(2);
  234. int Deck2EQMid = amux1.AnalogRead(6) / 8;
  235. //delay(2);
  236. int Deck1EQHigh = amux1.AnalogRead(7) / 8;
  237.  
  238. // Check to see if Mux2pin0 has changed values and send midi event - button on
  239.  
  240. if (Deck1Play != Deck1PlayState)
  241. {
  242. if (Deck1Play == 1)
  243. {
  244. Serial.println("Deck1Play");
  245. Serial.println("on");
  246. }
  247. }
  248.  
  249. // Check to see if button is released
  250.  
  251. if (Deck1Play == 0 && Deck1PlayState == 1)
  252. {
  253. Serial.println("Deck1Play");
  254. Serial.println("off");
  255. }
  256. Deck1PlayState=Deck1Play;
  257.  
  258. // Check to see if Mux2pin1 has changed values
  259.  
  260. if (Deck1Cue != Deck1CueState)
  261. {
  262. if (Deck1Cue == 1)
  263. {
  264. Serial.println("Deck1Cue");
  265. Serial.println("on");
  266. }
  267. }
  268.  
  269. if (Deck1Cue == 0 && Deck1CueState == 1)
  270. {
  271. Serial.println("Deck1Cue");
  272. Serial.println("off");
  273. }
  274. Deck1CueState=Deck1Cue;
  275.  
  276. // Check to see if Mux2pin2 has changed values
  277.  
  278. if (abs(Deck2Pitchfader - Deck2PitchfaderState) >=2)
  279. {
  280. Serial.println("Deck2Pitchfader");
  281. Serial.println(Deck2Pitchfader);
  282. Deck2PitchfaderState = Deck2Pitchfader;
  283. }
  284.  
  285. if (Deck2Pitchfader == 64)
  286. {
  287. digitalWrite(Deck2PitchfaderLED, HIGH);
  288. }
  289. else
  290. {
  291. digitalWrite(Deck2PitchfaderLED,LOW);
  292. }
  293.  
  294. // Check to see if Mux2pin3 has changed values
  295.  
  296. if (Deck2Pause != Deck2PauseState)
  297. {
  298. if (Deck2Pause == 2)
  299. {
  300. Serial.println("Deck2Pause");
  301. Serial.println("on");
  302. }
  303. }
  304.  
  305. // Check to see if button is released
  306.  
  307. if (Deck2Pause == 0 && Deck2PauseState == 2)
  308. {
  309. Serial.println("Deck2Pause");
  310. Serial.println("off");
  311. }
  312. Deck2PauseState=Deck2Pause;
  313.  
  314. // Check to see if Mux2pin4 has changed its values
  315.  
  316. if (abs(Deck2Volumefader - Deck2VolumefaderState) >= 2)
  317. {
  318. Serial.println("Deck2Volumefader");
  319. Serial.println(Deck2Volumefader);
  320. Deck2VolumefaderState=Deck2Volumefader;
  321. }
  322.  
  323. // Check to see if Mux2pin5 has changed its values
  324.  
  325. if (abs(Deck2EQLow - Deck2EQLowState) >= 2)
  326. {
  327. Serial.println("Deck2EQLow");
  328. Serial.println(Deck2EQLow);
  329. Deck2EQLowState=Deck2EQLow;
  330. }
  331.  
  332. // Check to see if Mux2pin6 has changed its values
  333.  
  334. if (abs(Deck2EQMid - Deck2EQMidState) >= 2)
  335. {
  336. Serial.println("Deck2EQMid");
  337. Serial.println(Deck2EQMid);
  338. Deck2EQMidState=Deck2EQMid;
  339. }
  340.  
  341. // Check to see if Mux2pin7 has changed its values
  342.  
  343. if (abs(Deck1EQHigh - Deck1EQHighState) >= 2)
  344. {
  345. Serial.println("Deck1EQHigh");
  346. Serial.println(Deck1EQHigh);
  347. Deck1EQHighState=Deck1EQHigh;
  348. }
  349.  
  350. // END OF MUX2
  351.  
  352. // Read the values from the pots and buttons from MUX3
  353. int Deck2Play = amux2.AnalogRead (0) / 511;
  354. //delay(2);
  355. int Deck1PBM = amux2.AnalogRead(1) / 511;
  356. //delay(2);
  357. int Deck2Cue = amux2.AnalogRead(2) / 511;
  358. //delay(2);
  359. int Deck1PBP = amux2.AnalogRead(3) / 511;
  360. //delay(2);
  361. int Deck2Filter = amux2.AnalogRead(4) / 8;
  362. //delay(2);
  363. int MasterVolumefader = amux2.AnalogRead(5) / 8;
  364. //delay(2);
  365. int Deck2EQHigh = amux2.AnalogRead(6) / 8;
  366. //delay(2);
  367. int Crossfader = amux2.AnalogRead(7) / 8;
  368.  
  369. // Check to see if Mux3pin0 has changed values and send midi event - button on
  370.  
  371. if (Deck2Play != Deck2PlayState)
  372. {
  373. if (Deck2Play == 1)
  374. {
  375. Serial.println("Deck2Play");
  376. Serial.println("on");
  377. }
  378. }
  379.  
  380. // Check to see if button is released
  381.  
  382. if (Deck2Play == 0 && Deck2PlayState == 1)
  383. {
  384. Serial.println("Deck2Play");
  385. Serial.println("off");
  386. }
  387. Deck2PlayState=Deck2Play;
  388.  
  389. // Check to see if Mux3pin1 has changed values
  390.  
  391. if (Deck1PBM != Deck1PBMState)
  392. {
  393. if (Deck1PBM == 1)
  394. {
  395. Serial.println("Deck1PBM");
  396. Serial.println("on");
  397. }
  398. }
  399.  
  400. if (Deck1PBM == 0 && Deck1PBMState == 1)
  401. {
  402. Serial.println("Deck1PBM");
  403. Serial.println("off");
  404. }
  405. Deck1PBMState=Deck1PBM;
  406.  
  407. // Check to see if Mux3pin2 has changed values
  408.  
  409. if (Deck2Cue != Deck2CueState)
  410. {
  411. if (Deck2Cue == 1)
  412. {
  413. Serial.println("Deck2Cue");
  414. Serial.println("on");
  415. Serial.println(Deck2Cue);
  416. Serial.println(Deck2CueState);
  417. }
  418. }
  419.  
  420. if (Deck2Cue == 0 && Deck2CueState == 1)
  421. {
  422. Serial.println("Deck2Cue");
  423. Serial.println("off");
  424. // Serial.println(Deck2Cue);
  425. // Serial.println(Deck2CueState);
  426. }
  427. Deck2CueState=Deck2Cue;
  428.  
  429. // Check to see if Mux3pin3 has changed values
  430.  
  431. if (Deck1PBP != Deck1PBPState)
  432. {
  433. if (Deck1PBP== 1)
  434. {
  435. Serial.println("Deck1PBP");
  436. Serial.println("on");
  437. }
  438. }
  439.  
  440. // Check to see if button is released
  441.  
  442. if (Deck1PBP == 0 && Deck1PBPState ==1)
  443. {
  444. Serial.println("Deck1PBP");
  445. Serial.println("off");
  446. Serial.println(Deck1PBP);
  447. Serial.println(Deck1PBPState);
  448. }
  449. Deck1PBPState=Deck1PBP;
  450.  
  451. // Check to see if Mux3pin4 has changed its values
  452.  
  453. if (abs(Deck2Filter - Deck2FilterState) >= 2)
  454. {
  455. Serial.println("Deck2Filter");
  456. Serial.println(Deck2Filter);
  457. Deck2FilterState=Deck2Filter;
  458. }
  459.  
  460. // Check to see if Mux3pin5 has changed its values
  461.  
  462. if (abs(MasterVolumefader - MasterVolumefaderState) >= 2)
  463. {
  464. Serial.println("MasterVolumefader");
  465. Serial.println(MasterVolumefader);
  466. MasterVolumefaderState=MasterVolumefader;
  467. }
  468.  
  469. // Check to see if Mux3pin6 has changed its values
  470.  
  471. if (abs(Deck2EQHigh - Deck2EQHighState) >= 2)
  472. {
  473. Serial.println("Deck2EQHigh");
  474. Serial.println(Deck2EQHigh);
  475. Deck2EQHighState=Deck2EQHigh;
  476. }
  477.  
  478. // Check to see if Mux3pin7 has changed its values
  479.  
  480. if (abs(Crossfader - CrossfaderState) >= 2)
  481. {
  482. Serial.println("Crossfader");
  483. Serial.println(Crossfader);
  484. CrossfaderState=Crossfader;
  485. }
  486.  
  487. // END OF MUX3
  488.  
  489. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement