can i use rotary encoders with mcp23017 as absolutecc? #1091
Unanswered
JuanFCulliganpy
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, i will know if its possible to use otary encoders with mcp23017 as absolutecc mode, i found this code(see bellow) but it is for pitchbend and when i move ccw it down to 0, and when i move cw it increase good `#include <Wire.h>
#include <Control_Surface.h>
#include <AH/Hardware/MCP23017Encoders.hpp>
// Type for the MCP23017 encoders (translates encoder pulses to position)
using WireType = decltype(Wire); // The type of I²C driver to use
using EncoderPositionType = uint8_t; // The type for saving encoder positions
using MCPEncoderType = MCP23017Encoders<WireType, EncoderPositionType>;
using uint16 = uint16_t;
// Type for the MIDI encoders (translates position to MIDI messages)
struct PBMCPEncoder : GenericMIDIAbsoluteEncoder<MCPEncoderType::MCP23017Encoder, PitchBendSender<14>> {
PBMCPEncoder(MCPEncoderType::MCP23017Encoder enc, MIDIAddress address, int16_t multiplier = 600, uint8_t pulsesPerStep = 4)
: GenericMIDIAbsoluteEncoder(std::move(enc), address, multiplier, pulsesPerStep, {}) {}
};
USBMIDI_Interface midi;
//USBDebugMIDI_Interface midi;
// Create an object that manages the 8 encoders connected to the MCP23017.
MCPEncoderType encV {Wire, 0x27, 4};
// │ │ └─ Interrupt pin
// │ └────── Address offset
// └──────────── I²C interface
// Sends Pitch Bend messages
PBMCPEncoder pbencodersVOL[] {
{encV[0], MCU::VOLUME_1},
{encV[1], MCU::VOLUME_2},
{encV[2], MCU::VOLUME_3},
{encV[3], MCU::VOLUME_4},
{encV[4], MCU::VOLUME_5},
{encV[5], MCU::VOLUME_6},
{encV[6], MCU::VOLUME_7},
{encV[7], MCU::VOLUME_8},
};
// Create objects that receives Pitch Bend messages from DAW channels
PBValue enc_values[] = {
{MCU::VOLUME_1},
{MCU::VOLUME_2},
{MCU::VOLUME_3},
{MCU::VOLUME_4},
{MCU::VOLUME_5},
{MCU::VOLUME_6},
{MCU::VOLUME_7},
{MCU::VOLUME_8}
};
// Create some array to store encoder's position
uint16 prev_positions [8];
uint16 incoming_values [8];
uint16 new_positions [8];
void setup() {
Control_Surface.begin();
Wire.begin(); // Must be called before enc.begin()
Wire.setClock(800000);
encV.begin(); // Initialize the MCP23017
}
void loop() {
for (int i = 0; i < 8; i++) {
prev_positions[i] = pbencodersVOL[i].getValue();
}
static constexpr decltype(millis()) timeout = 1000;
static decltype(millis()) prev_enc_move_time = -timeout;
for (int i = 0; i < 8; i++) {
new_positions[i] = pbencodersVOL[i].getValue();
incoming_values[i] = enc_values[i].getValue();
bool dirty = incoming_values[i] != new_positions[i];
// Keep track of when the user last moved the encoder.
}
}` thanks in advice. keep safe
Beta Was this translation helpful? Give feedback.
All reactions