-
Notifications
You must be signed in to change notification settings - Fork 161
Open
Description
Describe the bug
the notefastled sketch run nicely on my teensy but as soon as I want to incorporate it with my 16 encoders on mcp23017 led stop neopixels strip stop lighting
To Reproduce
Expected behavior
receiving midi notes sent from ableton and use it to light fastled
while my encoders send midi cc to ableton
Code
#include <FastLED.h>
#include <Control_Surface.h>
#include <SPI.h>
//#include <ILI9341_t3.h>
#include <AH/Hardware/MCP23017Encoders.hpp>
#include <Wire.h>
// Define the array of leds.
Array<CRGB, 8> leds {};
// The data pin with the strip connected.
constexpr uint8_t ledpin = 2;
NoteRangeFastLED<leds.length> midiled {leds, MIDI_Notes::C[4]};
//USBDebugMIDI_Interface midi;
USBMIDI_Interface midi;
//////ENCODERS/////
// 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 = 1)
: 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, 0x20, interrupt_pin};
// │ │ └─ Interrupt pin
// │ └────── Address offset
// └──────────── I²C interface
const uint8_t interrupt_pin2 = 6;
// 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
// Instantiate 8 MIDI rotary encoders.
CCMCPEncoder ccencoders[] {
{enc[0], {1, CHANNEL_16},-1,4},
{enc[1], {2, CHANNEL_16},-1,4},
{enc[2], {3, CHANNEL_16},-1,4},
{enc[3], {4, CHANNEL_16},-1,4},
{enc[4], {5, CHANNEL_16},-1,4},
{enc[5], {6, CHANNEL_16},-1,4},
{enc[6], {7, CHANNEL_16},-1,4},
{enc[7], {8, CHANNEL_16},-1,4},
};
// Instantiate 8 MIDI rotary encoders.
CCMCPEncoder ccencoders2[] {
{enc2[0], {9, CHANNEL_16},-1,4},
{enc2[1], {10, CHANNEL_16},1,4},
{enc2[2], {11, CHANNEL_16},-1,4},
{enc2[3], {12, CHANNEL_16},-1,4},
{enc2[4], {13, CHANNEL_16},-1,4},
{enc2[5], {14, CHANNEL_16},-1,4},
{enc2[6], {15, CHANNEL_16},-1,4},
{enc2[7], {16, CHANNEL_16},-1,4},
};
////mux
CD74HC4067 mux1 = {
14, // numéro de broche de l'arduino
{2, 3, 4, 5} // numéro de pins de l'arduino sur lesquels sont branchés tous les multiplexeurs apellés mux S0, S1, S2
};
void isr() {
enc.update(); // Read the state of the encoders and update the positions
enc2.update();
}
CCValue cc1 []= {
{{1, CHANNEL_16}},
{{2, CHANNEL_16}},
{{3, CHANNEL_16}},
{{4, CHANNEL_16}},
{{5, CHANNEL_16}},
{{6, CHANNEL_16}},
{{7, CHANNEL_16}},
{{8, CHANNEL_16}},
};
////*/
CCButtonLatched buttontransportmomentary[] = {
{mux1.pin(0), {110, CHANNEL_1}},
{mux1.pin(1), {109, CHANNEL_1}},
{mux1.pin(2), {108, CHANNEL_1}},
{mux1.pin(3), {107, CHANNEL_1}},
{mux1.pin(4), {106, CHANNEL_1}},
{mux1.pin(5), {105, CHANNEL_1}},
{mux1.pin(6), {104, CHANNEL_1}},
{mux1.pin(7), {103, CHANNEL_1}},
{mux1.pin(15), {110, CHANNEL_2}},//numéro de bank correspondant/indique que le changement de bank change le canal midi (+8 car on a 8 adresses par bank)/pin sur laquelle le controleur est branché/numéro de cc/numéro de canal midi
{mux1.pin(14), {109, CHANNEL_2}},
{mux1.pin(13), {108, CHANNEL_2}},
{mux1.pin(12), {107, CHANNEL_2}},
{mux1.pin(11), {106, CHANNEL_2}},
{mux1.pin(10), {105, CHANNEL_2}},
{mux1.pin(9), {104, CHANNEL_2}},
{mux1.pin(8), {103, CHANNEL_2}},
};
void setup() {
FastLED.addLeds<NEOPIXEL, ledpin>(leds.data, leds.length);
FastLED.setCorrection(TypicalPixelString);
midiled.setBrightness(128);
Control_Surface.begin();
Wire.begin(); // Must be called before enc.begin()
Wire.setClock(800000);
enc.begin(); // Initialize the MCP23017
enc2.begin();
attachInterrupt(digitalPinToInterrupt(interrupt_pin), isr, LOW);
attachInterrupt(digitalPinToInterrupt(interrupt_pin2), isr, LOW);
RelativeCCSender::setMode(TRACKTION_RELATIVE);
usbMIDI.begin(); // Initialize the MIDI interface
}
void loop() {
usbMIDI.read();
Control_Surface.loop();
if (midiled.getDirty()) { // If the colors changed
FastLED.show(); // Update the LEDs with the new colors
midiled.clearDirty(); // Clear the dirty flag
}
}
Metadata
Metadata
Assignees
Labels
No labels