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.

121 lines
4.0 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 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. //MCP23017 I2C addresses 0,1,3 and 4 (2 is unused yet)
  8. INPUT_MCP23017 input_MCP23017_0;
  9. INPUT_MCP23017 input_MCP23017_1;
  10. INPUT_MCP23017 input_MCP23017_3;
  11. INPUT_MCP23017 input_MCP23017_4;
  12. //three 74HC4051 on analog pins A0,A1,A2; select on digital pins 8,9,10
  13. INPUT_74HC4051 input_4051_A0;
  14. INPUT_74HC4051 input_4051_A1;
  15. INPUT_74HC4051 input_4051_A2;
  16. //left jogwheel, sends CC message on controller id 0x7A with value 65 (increment)
  17. void rotary_encoder_jogwheel_left_inc() {
  18. Midi.controlChange(MIDI_MAX_DATA-5,65);
  19. }
  20. //left jogwheel, sends CC message on controller id 0x7A with value 63 (decrement)
  21. void rotary_encoder_jogwheel_left_dec() {
  22. Midi.controlChange(MIDI_MAX_DATA-5,63);
  23. }
  24. //right jogwheel, sends CC message on controller id 0x79 with value 65 (increment)
  25. void rotary_encoder_jogwheel_right_inc() {
  26. Midi.controlChange(MIDI_MAX_DATA-6,65);
  27. }
  28. //right jogwheel, sends CC message on controller id 0x79 with value 63 (decrement)
  29. void rotary_encoder_jogwheel_right_dec() {
  30. Midi.controlChange(MIDI_MAX_DATA-6,63);
  31. }
  32. //browse, sends note-on/off signal with note 0x36 [equals to default digital callback note] (increment)
  33. void rotary_encoder_browse_inc() {
  34. Midi.noteOn(3 * 16 + 6, MIDI_MAX_DATA);
  35. Midi.noteOff(3 * 16 + 6);
  36. }
  37. //browse, sends note-on/off signal with note 0x35 [equals to default digital callback note] (decrement)
  38. void rotary_encoder_browse_dec() {
  39. Midi.noteOn(3 * 16 + 5, MIDI_MAX_DATA);
  40. Midi.noteOff(3 * 16 + 5);
  41. }
  42. //three rotary encoders connected to input_MCP23017_1 and input_MCP23017_3
  43. ROTARY_ENCODER rotary_encoder_jogwheel_left(rotary_encoder_jogwheel_left_inc, rotary_encoder_jogwheel_left_dec); //input_MCP23017_1 pins 6 and 7
  44. ROTARY_ENCODER rotary_encoder_jogwheel_right(rotary_encoder_jogwheel_right_inc, rotary_encoder_jogwheel_right_dec); //input_MCP23017_3 pins 9 and 1
  45. ROTARY_ENCODER rotary_encoder_browse(rotary_encoder_browse_inc,rotary_encoder_browse_dec); //input_MCP23017_3 pins 5 and 6
  46. void setup() {
  47. //initialize MIDI
  48. Midi.begin();
  49. //initialize MCP23017s
  50. input_MCP23017_0.begin(0,digitalCallback);
  51. input_MCP23017_1.begin(1,digitalCallback1);
  52. input_MCP23017_3.begin(3,digitalCallback3);
  53. input_MCP23017_4.begin(4,digitalCallback);
  54. //initialize 74HC4051s
  55. input_4051_A0.begin(A0,8,9,10,analogCallback);
  56. input_4051_A1.begin(A1,8,9,10,analogCallback);
  57. input_4051_A2.begin(A2,8,9,10,analogCallback);
  58. }
  59. void loop() {
  60. //loop MCP23017s for callbacks
  61. input_MCP23017_0.loop();
  62. input_MCP23017_1.loop();
  63. input_MCP23017_3.loop();
  64. input_MCP23017_4.loop();
  65. //loop 74HC4051s for callback
  66. input_4051_A0.loop();
  67. input_4051_A1.loop();
  68. input_4051_A2.loop();
  69. }
  70. //callback for analog, sends CC message with unique controller id
  71. void analogCallback(int id, int pin, int value) {
  72. Midi.controlChange((id-A0) * 8 + pin,value);
  73. }
  74. //default callback for buttons, sends note-on/off message with unique note value
  75. void digitalCallback(int id, int pin, int value) {
  76. if (value == HIGH)
  77. Midi.noteOn(id * 16 + pin, MIDI_MAX_DATA);
  78. else Midi.noteOff(id * 16 + pin);
  79. }
  80. //callback for input_MCP23017_1, checks for rotary_encoder_jogwheel_left, otherwise default callback
  81. void digitalCallback1(int id, int pin, int value) {
  82. if (pin == 6)
  83. rotary_encoder_jogwheel_left.setPinA(value);
  84. if (pin == 7)
  85. rotary_encoder_jogwheel_left.setPinB(value);
  86. if (pin != 6 && pin !=7)
  87. digitalCallback(id,pin,value);
  88. }
  89. //callback for input_MCP23017_3, checks for rotary_encoder_jogwheel_right and rotary_encoder_browse, otherwise default callback
  90. void digitalCallback3(int id, int pin, int value) {
  91. if (pin == 9)
  92. rotary_encoder_jogwheel_right.setPinA(value);
  93. if (pin == 10)
  94. rotary_encoder_jogwheel_right.setPinB(value);
  95. if (pin == 6)
  96. rotary_encoder_browse.setPinA(value);
  97. if (pin == 5)
  98. rotary_encoder_browse.setPinB(value);
  99. if (pin!= 9 && pin != 10 && pin != 6 && pin != 5)
  100. digitalCallback(id,pin,value);
  101. }