sources and files for the bombatuino project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.9 KiB

12 years ago
  1. #include <Wire.h>
  2. #include <bombatuino_INPUT_MCP23017.h>
  3. #include <bombatuino_INPUT_74HC4051.h>
  4. #include <bombatuino_MIDI.h>
  5. #include <bombatuino_ROTARY_ENCODER.h>
  6. MIDI Midi;
  7. INPUT_MCP23017 input_MCP23017_0;
  8. INPUT_MCP23017 input_MCP23017_1;
  9. INPUT_MCP23017 input_MCP23017_3;
  10. INPUT_MCP23017 input_MCP23017_4;
  11. INPUT_74HC4051 input_4051_A0;
  12. INPUT_74HC4051 input_4051_A1;
  13. INPUT_74HC4051 input_4051_A2;
  14. ROTARY_ENCODER rotary_encoder_jogwheel_left(rotary_encoder_jogwheel_left_inc, rotary_encoder_jogwheel_left_dec);
  15. ROTARY_ENCODER rotary_encoder_jogwheel_right(rotary_encoder_jogwheel_right_inc, rotary_encoder_jogwheel_right_dec);
  16. ROTARY_ENCODER rotary_encoder_browse(rotary_encoder_browse_inc,rotary_encoder_browse_dec);
  17. void setup() {
  18. Midi.begin();
  19. input_MCP23017_0.begin(0,digitalCallback);
  20. input_MCP23017_1.begin(1,digitalCallback1);
  21. input_MCP23017_3.begin(3,digitalCallback3);
  22. input_MCP23017_4.begin(4,digitalCallback);
  23. input_4051_A0.begin(A0,8,9,10,analogCallback);
  24. input_4051_A1.begin(A1,8,9,10,analogCallback);
  25. input_4051_A2.begin(A2,8,9,10,analogCallback);
  26. }
  27. void loop() {
  28. input_MCP23017_0.loop();
  29. input_MCP23017_1.loop();
  30. input_MCP23017_3.loop();
  31. input_MCP23017_4.loop();
  32. input_4051_A0.loop();
  33. input_4051_A1.loop();
  34. input_4051_A2.loop();
  35. }
  36. void analogCallback(int id, int pin, int value) {
  37. Midi.controlChange((id-A0) * 8 + pin,value);
  38. }
  39. void digitalCallback(int id, int pin, int value) {
  40. if (value == HIGH)
  41. Midi.noteOn(id * 16 + pin, MIDI_MAX_DATA);
  42. else Midi.noteOff(id * 16 + pin);
  43. }
  44. void digitalCallback1(int id, int pin, int value) {
  45. if (pin == 6)
  46. rotary_encoder_jogwheel_left.setPinA(value);
  47. if (pin == 7)
  48. rotary_encoder_jogwheel_left.setPinB(value);
  49. if (pin != 6 && pin !=7) {
  50. if (value == HIGH)
  51. Midi.noteOn(id * 16 + pin, MIDI_MAX_DATA);
  52. else Midi.noteOff(id * 16 + pin);
  53. }
  54. }
  55. void digitalCallback3(int id, int pin, int value) {
  56. if (pin == 9)
  57. rotary_encoder_jogwheel_right.setPinA(value);
  58. if (pin == 10)
  59. rotary_encoder_jogwheel_right.setPinB(value);
  60. if (pin == 6)
  61. rotary_encoder_browse.setPinA(value);
  62. if (pin == 5)
  63. rotary_encoder_browse.setPinB(value);
  64. if (pin!= 9 && pin != 10 && pin != 6 && pin != 5){
  65. if (value == HIGH)
  66. Midi.noteOn(id * 16 + pin, MIDI_MAX_DATA);
  67. else Midi.noteOff(id * 16 + pin);
  68. }
  69. }
  70. //left jogwheel
  71. void rotary_encoder_jogwheel_left_inc() {
  72. Midi.controlChange(MIDI_MAX_DATA-5,65);
  73. }
  74. void rotary_encoder_jogwheel_left_dec() {
  75. Midi.controlChange(MIDI_MAX_DATA-5,63);
  76. }
  77. //right jogwheel
  78. void rotary_encoder_jogwheel_right_inc() {
  79. Midi.controlChange(MIDI_MAX_DATA-6,65);
  80. }
  81. void rotary_encoder_jogwheel_right_dec() {
  82. Midi.controlChange(MIDI_MAX_DATA-6,63);
  83. }
  84. //Browse
  85. void rotary_encoder_browse_inc() {
  86. Midi.noteOn(3 * 16 + 6, MIDI_MAX_DATA);
  87. Midi.noteOff(3 * 16 + 6);
  88. }
  89. void rotary_encoder_browse_dec() {
  90. Midi.noteOn(3 * 16 + 5, MIDI_MAX_DATA);
  91. Midi.noteOff(3 * 16 + 5);
  92. }