Controllers.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef CONTROLLERS_H
  2. #define CONTROLLERS_H
  3. #include <EncoderButton.h>
  4. #include <Adafruit_MCP23X17.h>
  5. #include "Arduino.h"
  6. #include "MIDIUSB.h"
  7. // Uncomment this line if you want pin and values printed on the serial, remember to open a console because it waits until a connection is established.
  8. #define DEBUG
  9. // Uncomment this line if you want to disable MIDI output, you have to comment the #include "MIDIUSB.h" as well
  10. //#define DUMMY
  11. // Analog controls (sliders and potentiometers), the deadzone is the smallest increment that the control must have to trigger the effect.
  12. #define DEAD_ZONE 15
  13. // Stickyness is a deazone that lies around extreme positions (0-1023) and the middle (511, but trimmable) of readings.
  14. #define STICKYNESS 30
  15. // Time, in ms, needed for a long press
  16. #define LONG_INTERVAL 1000
  17. void noteOn(byte channel, byte pitch, byte velocity);
  18. void noteOff(byte channel, byte pitch, byte velocity);
  19. void controlChange(byte channel, byte control, byte value);
  20. void eb_Encoder(EncoderButton& eb);
  21. class AnalogControl {
  22. private:
  23. int pin;
  24. byte effect;
  25. int middle;
  26. int value;
  27. int prev_value;
  28. public:
  29. AnalogControl(int pin, byte effect, int middle);
  30. void init();
  31. void checkStatus();
  32. };
  33. class DigitalButton {
  34. private:
  35. int pin;
  36. bool pressed;
  37. long debounce;
  38. byte effect;
  39. byte effect_toggle;
  40. bool toggled;
  41. byte effect_long;
  42. byte effect_long_toggle;
  43. bool long_toggled;
  44. bool long_pressed;
  45. public:
  46. DigitalButton(int pin, byte effect, byte effect_toggle, byte effect_long, byte effect_long_toggle);
  47. void init();
  48. void checkStatus();
  49. };
  50. class MCP23017_Expander {
  51. private:
  52. Adafruit_MCP23X17 mcp;
  53. int address;
  54. bool pressed[16];
  55. byte effects[16];
  56. byte effects_toggle[16];
  57. bool toggled[16];
  58. byte effects_long[16];
  59. byte effects_long_toggle[16];
  60. bool long_toggled[16];
  61. bool long_pressed[16];
  62. long debounce[16];
  63. public:
  64. MCP23017_Expander(int address, int effects[16], int effects_toggle[16], int effects_long[16], int effects_long_toggle[16]);
  65. void init();
  66. void checkStatus();
  67. };
  68. struct RotaryEncoderControl {
  69. EncoderButton rotary_encoder;
  70. byte effect;
  71. };
  72. class Mux {
  73. private:
  74. int pinSIG;
  75. int value[16];
  76. int prev_value[16];
  77. int mid_deadzone[16];
  78. public:
  79. int effects[16];
  80. static int pinS0;
  81. static int pinS1;
  82. static int pinS2;
  83. static int pinS3;
  84. Mux(int pinSIG, int effects[16], int mid_deadzone[16]);
  85. void init();
  86. void checkStatus(byte selector);
  87. };
  88. #endif