Control-Surface icon indicating copy to clipboard operation
Control-Surface copied to clipboard

using absolute rotary encoder with mcp23017

Open benwadub opened this issue 3 years ago • 0 comments
trafficstars

hi, i like to use few encoders as absolute encoders wired on an mcp23017

Describe the solution you'd like i like to be able to use the class or equivalent of the ccabsoluteencoder inside an array of encoder

something like this: note the first array would use absolute encoders and the other the actual mcp encoders class that work nicely


// Type for the MCP23017 encoders (translates encoder pulses to position)
using WireType = decltype(Wire);     // The type of I²C driver to use
using EncoderPositionType = int32_t; // The type for saving encoder positions
constexpr bool IntSafe = true;       // Make it safe to call `update` in an ISR
using MCPEncoderType = MCP23017Encoders<WireType, EncoderPositionType, IntSafe>;

// Type for the MIDI encoders (translates position to MIDI messages)
struct CCMCPEncoder : GenericMIDIRotaryEncoder<MCPEncoderType::MCP23017Encoder,
                                               RelativeCCSender> {
  CCMCPEncoder(MCPEncoderType::MCP23017Encoder enc, MIDIAddress address,
               int16_t multiplier = 1, uint8_t pulsesPerStep = 4)
    : GenericMIDIRotaryEncoder(std::move(enc), address, multiplier,
                               pulsesPerStep, {}) {}
                               
};

const uint8_t interrupt_pin = 7;
// Create an object that manages the 8 encoders connected to the MCP23017.
MCPEncoderType enc {Wire, 0x27, interrupt_pin};
//                  │     │    └─ Interrupt pin
//                  │     └────── Address offset
//                  └──────────── I²C interface
const uint8_t interrupt_pin2 = 8;
// Create an object that manages the 8 encoders connected to the MCP23017.
MCPEncoderType enc2 {Wire, 0x21, interrupt_pin2};
//                  │     │    └─ Interrupt pin
//                  │     └────── Address offset
//                  └──────────── I²C interface
const uint8_t interrupt_pin3 = 9;
// Create an object that manages the 8 encoders connected to the MCP23017.
MCPEncoderType enc3 {Wire, 0x22, interrupt_pin3};
//                  │     │    └─ Interrupt pin
//                  │     └────── Address offset
//                  └──────────── I²C interface
// Instantiate 8 MIDI rotary encoders.
CCAbsoluteEncoder ccencoders[] {
  {enc[0], {44, CHANNEL_16},1,4},
  {enc[1], {45, CHANNEL_16},1,4},
  {enc[2], {46, CHANNEL_16},1,4},
  {enc[3], {47, CHANNEL_16},1,4},
  {enc[4], {48, CHANNEL_16},1,4},
  {enc[5], {49, CHANNEL_16},1,4},
  {enc[6], {50, CHANNEL_16},1,4},
  {enc[7], {51, CHANNEL_16},1,4},
  };
  // Instantiate 8 MIDI rotary encoders.
CCMCPEncoder ccencoders2[] {
  {enc2[0], {52, CHANNEL_16},1,4},
  {enc2[1], {53, CHANNEL_16},1,4},
  {enc2[2], {54, CHANNEL_16},1,4},
  {enc2[3], {55, CHANNEL_16},1,4},
  {enc2[4], {56, CHANNEL_16},1,4},
  {enc2[5], {57, CHANNEL_16},1,4},
  {enc2[6], {58, CHANNEL_16},1,4},
  {enc2[7], {59, CHANNEL_16},1,4},
  };
  CCMCPEncoder ccencoders3[] {
  {enc3[0], {60, CHANNEL_16},1,4},
  {enc3[1], {61, CHANNEL_16},1,4},
  {enc3[2], {62, CHANNEL_16},1,4},
  {enc3[3], {63, CHANNEL_16},1,4},
  {enc3[4], {64, CHANNEL_16},1,4},
  {enc3[5], {65, CHANNEL_16},1,4},
  {enc3[6], {66, CHANNEL_16},1,4},
  {enc3[7], {67, CHANNEL_16},1,4},
  
  };
  void isr() {
  enc.update(); // Read the state of the encoders and update the positions
  enc2.update();
  enc3.update();
  }

i don t know at all if that is something doable but that would help me a lot!

benwadub avatar Jan 31 '22 19:01 benwadub