#include <Wire.h>
#include <Adafruit_MCP23X17.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_NeoPixel.h>
#include <MIDI.h>
//bank numder
//int numb=0;
//int pres=0;
// MCP23017 Instances
Adafruit_MCP23X17 mcp0;
Adafruit_MCP23X17 mcp1;
// OLED Display
#define OLED_ADDR 0x3C
Adafruit_SSD1306 display(128, 64, &Wire, -1);
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// NeoPixel
#define PIN 13 // for the NeoPixel data line.
#define Neopixel 16 // for the NeoPixel data line.
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Neopixel, PIN, NEO_GRB + NEO_KHZ800);
// MIDI
MIDI_CREATE_DEFAULT_INSTANCE();
void handleNoteOn(byte channel, byte pitch, byte velocity) {
Serial.print("Note On, channel: ");
Serial.print(channel);
Serial.print(", pitch: ");
Serial.print(pitch);
Serial.print(", velocity: ");
Serial.println(velocity);
int pixel = pitch % Neopixel; // Map pitch to a pixel index
strip.setPixelColor(pixel, velocity, 0, 0); // Light up pixel with a color based on velocity
strip.show();
}
void handleNoteOff(byte channel, byte pitch, byte velocity) {
Serial.print("Note Off, channel: ");
Serial.print(channel);
Serial.print(", pitch: ");
Serial.print(pitch);
Serial.print(", velocity: ");
Serial.println(velocity);
int pixel = pitch % Neopixel; // Map pitch to a pixel index
strip.setPixelColor(pixel, 0, 0, 0); // Turn off the pixel
strip.show();
}
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("Cubase v5");
display.display();
Serial.begin(9600);
Wire.begin(21, 22);
// MCP23017
mcp0.begin_I2C(); // Initialize MCP23017 at address A
mcp1.begin_I2C(0x23); // Initialize MCP23017 at address B
// NeoPixel
strip.begin();
strip.show(); // Initialize all pixels to 'off'
strip.setBrightness(20);
// Setup input pins with pull-ups for both MCP23017 chips
for (int i = 0; i < 16; i++) {
mcp0.pinMode(i, INPUT_PULLUP);
mcp1.pinMode(i, INPUT_PULLUP);
}
// MIDI
MIDI.begin(MIDI_CHANNEL_OMNI);
MIDI.setHandleNoteOn(handleNoteOn);
MIDI.setHandleNoteOff(handleNoteOff);
}
void loop() {
// Handle MIDI input
MIDI.read();
// The rest of your loop code to handle MCP23017 inputs and NeoPixel updates
// MCP0 inputs
if (mcp0.digitalRead(0) == LOW) {
Serial.println("MCP0-1 UP 49"); //monitor
strip.setPixelColor(14, 255, 0, 255); //neopixel
strip.show(); //neopixel
display.clearDisplay(); //i2c Screen
display.setTextColor(WHITE); //i2c Screen
display.setTextSize(2); //i2c Screen
display.setCursor(10, 10); //i2c Screen
display.println("MCP0-1 UP MIDI 49"); //i2c Screen
display.display(); //i2c Screen
MIDI.sendNoteOn(49, 127, 1); // Send MIDI Note On (C#2, velocity 127, channel 1)
delay(100);
} else {
strip.setPixelColor(14, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(49, 0, 1); // Send MIDI Note Off (C#2, velocity 0, channel 1)
}
////////////////////////////////////////////////////////////////////////////////////////////////
if (mcp0.digitalRead(1) == LOW) {
Serial.println("MCP0-2 Down 48");
strip.setPixelColor(15, 255, 0, 255);
strip.show();
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-2 Down 48");
display.display();
MIDI.sendNoteOn(48, 127, 1); // Send MIDI Note On (C2, velocity 127, channel 1)
delay(200);
}
else {
strip.setPixelColor(15, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(48, 0, 1); // Send MIDI Note Off (C2, velocity 0, channel 1)
}
if (mcp0.digitalRead(2) == LOW) {
Serial.println("MCP0-3 Rotary Encoder 1 B");
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-3 RE1 B");
display.display();
MIDI.sendNoteOn(62, 127, 1); // Send MIDI Note On (D4, velocity 127, channel 1)
delay(200);
}
else {
strip.setPixelColor(13, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(62, 0, 1); // Send MIDI Note Off (D4, velocity 0, channel 1)
}
if (mcp0.digitalRead(3) == LOW) {
Serial.println("MCP0-4 Rotary Encoder 1 A");
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-4 RE1 A");
display.display();
delay(250);
}
if (mcp0.digitalRead(4) == LOW) {
Serial.println("MCP0-5 Rotary Encoder 2 A ");
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-5 Rotary Encoder 2 A ");
display.display();
MIDI.sendNoteOn(93, 127, 1); //A5 94 Send MIDI Note On (A5, velocity 127, channel 1)
delay(200);
}
else {
strip.setPixelColor(4, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(93, 0, 1); //A5 93 Send MIDI Note Off (A5, velocity 0, channel 1)Mackie ff
}
///////////////////////////////////////////////////////////////////////////////////////////////
if (mcp0.digitalRead(5) == LOW) {
Serial.println("MCP0-6 Rotary Encoder 2 B");
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-6 RE2 B");
display.display();
delay(50);
}
if (mcp0.digitalRead(6) == LOW) {
Serial.println("MCP0-7 Rotary Encoder 1 SW m44");
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-7 RE1 SW EQ m44");
display.display();
MIDI.sendNoteOn(44, 127, 1); //G#1 44 Send MIDI Note On (G#1, velocity 127, channel 1)Mackie EQ
delay(200);
}
else {
strip.setPixelColor(4, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(44, 0, 1); //G#1 44 Send MIDI Note Off (G#1, velocity 0, channel 1)Mackie EQ
}
///////////////////////////////////////////////////////////////////////////////////////////////
if (mcp0.digitalRead(7) == LOW) {
Serial.println("MCP0-8 Rotary Encoder 2 SW");
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-8 RE2 SW sends m76");
display.display();
MIDI.sendNoteOn(76, 127, 1); //E4 76 Send MIDI Note On (A5, velocity 127, channel 1)Mackie Sends
delay(200);
}
else {
MIDI.sendNoteOff(76, 0, 1); //E4 76 Send MIDI Note Off (A5, velocity 0, channel 1)Mackie Sends
}
///////////////////////////////////////////////////////////////////////////////////////////////
if (mcp0.digitalRead(8) == LOW) {
Serial.println("MCP0-9 Rotary Encoder 3 SW");
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-9 RE3 SW m78 mixer");
display.display();
MIDI.sendNoteOn(78, 127, 1); //F#4 78 Send MIDI Note On (F#4, velocity 127, channel 1)
delay(200);
}
else {
//strip.setPixelColor(4, 0, 0, 0); // Turn off NeoPixel
//strip.show();
MIDI.sendNoteOff(78, 0, 1); //F#4 78 Send MIDI Note Off (F#4, velocity 0, channel 1)Mackie ff
}
///////////////////////////////////////////////////////////////////////////////////////////////
if (mcp0.digitalRead(9) == LOW) {
Serial.println("MCP0-10 Rotary Encoder 3 A");
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-10 RE3 A");
display.display();
delay(50);
}
///////////////////////////////////////////////////////////////////////////////////////
if (mcp0.digitalRead(10) == LOW) {
Serial.println("MCP0-11 Rotary Encoder 3 B");
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-11 RE3 B");
display.display();
delay(50);
}
////////////////////////////////////////////////////////////////////////////////////////
if (mcp0.digitalRead(11) == LOW) {
Serial.println("MCP0-12 Rotary Encoder 4 SW");
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-12 RE4 SW");
display.display();
MIDI.sendNoteOn(80, 127, 1); //G#4 80 Send MIDI Note On (G#4, velocity 127, channel 1)Mackie Inst
delay(200);
}
else {
//strip.setPixelColor(4, 0, 0, 0); // Turn off NeoPixel
//strip.show();
MIDI.sendNoteOff(80, 0, 1); //G#4 80 Send MIDI Note Off (G#4, velocity 0, channel 1)Mackie Inst
}
///////////////////////////////////////////////////////////////////////////////////////////////
if (mcp0.digitalRead(12) == LOW) {
Serial.println("MCP0-13 Rotary Encoder 4 B");
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-13 RE4 B");
display.display();
delay(50);
}
//////////////////////////////////////////////////////////////////////////////////////////////
if (mcp0.digitalRead(13) == LOW) {
Serial.println("MCP0-14 Rotary Encoder 4 A");
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-14 RE4 A");
display.display();
delay(50);
}
////////////////////////////////////////////////////////////////////////////////////////////
if (mcp0.digitalRead(14) == LOW) {
Serial.println("MCP0-15 REWIND");
strip.setPixelColor(3, 0, 225, 225);
strip.show();
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-15 REWIND m91");
display.display();
MIDI.sendNoteOn(91, 127, 1); //91 Send MIDI Note On (G5, velocity 127, channel 1)REWIND
delay(200);
}
else {
strip.setPixelColor(3, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(91, 0, 1); // 91Send MIDI Note Off (G5, velocity 0, channel 1)REWIND
}
////////////////////////////////////////////////////////////////////////////////////////////
if (mcp0.digitalRead(15) == LOW) {
Serial.println("MCP0-16 LOC1");
strip.setPixelColor(2, 0, 0, 255);
strip.show();
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP0-16 LOC1 88");
display.display();
strip.show();
MIDI.sendNoteOn(88, 127, 1); // 88 Send MIDI Note On (E4, velocity 127, channel 1)
delay(200);
}
else {
strip.setPixelColor(2, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(88, 0, 1); // 88 Send MIDI Note Off (E4, velocity 0, channel 1)
}
///////////////////////////////////////////////////////////////////////////////////////////////
// MCP1 inputs
if (mcp1.digitalRead(0) == LOW) {
Serial.println("MCP1-1 B2");
strip.setPixelColor(10, 0, 255, 255);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-1 B2 F2");
display.display();
strip.show();
MIDI.sendNoteOn(55, 127, 1); //G2 55 Send MIDI Note On (G2, velocity 127, channel 1)F2 mackie
delay(200);
}
else {
strip.setPixelColor(10, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(55, 0, 1); //G2 55 Send MIDI Note Off (G2, velocity 0, channel 1)F2 mackie
}
///////////////////////////////////////////////////////////////////////////////////////////////
if (mcp1.digitalRead(1) == LOW) {
Serial.println("MCP1-2 B1");
strip.setPixelColor(11, 0, 255, 255);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-2 B1 F1");
display.display();
strip.show();
MIDI.sendNoteOn(54, 127, 1); //F#2 54 Send MIDI Note On (F#2, velocity 127, channel 1)Mackie F1
delay(200);
}
else {
strip.setPixelColor(11, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(54, 0, 1); //F#2 54 Send MIDI Note Off (F#2, velocity 0, channel 1)Mackie F1
}
///////////////////////////////////////////////////////////////////////////////////////////////
if (mcp1.digitalRead(2) == LOW) {
Serial.println("MCP1-3 Banp up");
strip.setPixelColor(12, 0, 255, 0);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-3 Bank up M47" );
display.display();
strip.show();
MIDI.sendNoteOn(47, 127, 1); //B1 47 Send MIDI Note On (B1, velocity 127, channel 1)Mackie Bank UP
delay(200);
}
else {
strip.setPixelColor(12, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(47, 0, 1); //B1 47 Send MIDI Note Off (B1, velocity 0, channel 1)Mackie Bank UP
}
///////////////////////////////////////////////////////////////////////////////////////////////
if (mcp1.digitalRead(3) == LOW) {
Serial.println("MCP1-4 Bank Down");
strip.setPixelColor(13, 0, 255, 0);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-4 Bank Down M46");
display.display();
strip.show();
MIDI.sendNoteOn(46, 127, 1); //A#1 46 Send MIDI Note On (A#1, velocity 127, channel 1)Mackie Bank DOWN
delay(200);
}
else {
strip.setPixelColor(13, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(46, 0, 1); //A#1 46 Send MIDI Note Off (A#1, velocity 0, channel 1)Mackie Bank DOWN
}
//////////////////////////////////////////////////////////////////////////
if (mcp1.digitalRead(4) == LOW) {
Serial.println("MCP1-5 MAIN RE EDIT");
//strip.setPixelColor(9, 0, 255, 0);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-5 mAIN M51 EDIT");
display.display();
strip.show();
MIDI.sendNoteOn(51, 127, 1); //D#2 51 Send MIDI Note On (D#2, velocity 127, channel 1)Mackie EDIT
delay(200);
}
else {
// strip.setPixelColor(13, 0, 0, 0); // Turn off NeoPixel
//strip.show();
MIDI.sendNoteOff(51, 0, 1); //D#2 51 Send MIDI Note Off (D#2, velocity 0, channel 1)Mackie EDIT
}
//////////////////////////////////////////////////////////////////////////
if (mcp1.digitalRead(5) == LOW) {
Serial.println("MCP1-6 MAIN RE A");
//strip.setPixelColor(10, 0, 255, 0);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-6 MAIN RE A");
display.display();
strip.show();
delay(500);
}
if (mcp1.digitalRead(6) == LOW) {
Serial.println("MCP1-7 MAIN RE B");
//strip.setPixelColor(11, 0, 255, 0);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-7 MAIN RE B");
display.display();
strip.show();
delay(500);
}
if (mcp1.digitalRead(7) == LOW) {
Serial.println("NOT USED");
// strip.setPixelColor(12, 0, 255, 0);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("NOT USED");
display.display();
strip.show();
delay(500);
}
if (mcp1.digitalRead(8) == LOW) {
Serial.println("MCP1-9 Stop");
strip.setPixelColor(4, 0, 255, 0);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-9 STOP 93");
display.display();
strip.show();
MIDI.sendNoteOn(93, 127, 1); //A5 94 Send MIDI Note On (A5, velocity 127, channel 1)
delay(200);
}
else {
strip.setPixelColor(4, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(93, 0, 1); //A5 93 Send MIDI Note Off (A5, velocity 0, channel 1)Mackie ff
}
///////////////////////////////////////////////////////////////////////////////////////////////
if (mcp1.digitalRead(9) == LOW) {
Serial.println("MCP1-10 Play");
strip.setPixelColor(5, 255, 255, 0);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-10 PLAY94");
display.display();
strip.show();
MIDI.sendNoteOn(94, 127, 1); //A#5 94 Send MIDI Note On (A#5, velocity 127, channel 1)
delay(200);
}
else {
strip.setPixelColor(5, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(94, 0, 1); //A#5 94 Send MIDI Note Off (A#5, velocity 0, channel 1)Mackie ff
}
////////////////////////////////////////////////////////////////////////////////////////////////
if (mcp1.digitalRead(10) == LOW) {
Serial.println("MCP1-11 Record");
strip.setPixelColor(6, 255, 0, 0);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-11 RECORD95");
display.display();
strip.show();
MIDI.sendNoteOn(95, 127, 1); //B5 95 Send MIDI Note On (B5, velocity 127, channel 1)
delay(200);
} else {
strip.setPixelColor(6, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(95, 0, 1); //B5 95 Send MIDI Note Off (B5, velocity 0, channel 1)Mackie ff
}
if (mcp1.digitalRead(11) == LOW) {
Serial.println("MCP1-12 Fastforword");
strip.setPixelColor(7, 0, 255, 255);
strip.show();
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-12 FASTFORWORD92");
display.display();
MIDI.sendNoteOn(92, 127, 1); // Send MIDI Note On (, velocity 127, channel 1)
delay(200);
} else {
strip.setPixelColor(7, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(92, 0, 1); // Send MIDI Note Off (, velocity 0, channel 1)Mackie ff
}
if (mcp1.digitalRead(12) == LOW) {
Serial.println("MCP1-13 LOOP 86");
strip.setPixelColor(1, 0, 255, 255);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-13 LOOP 86");
display.display();
strip.show();
MIDI.sendNoteOn(86, 127, 1); //D5 86 Send MIDI Note On (D5, velocity 127, channel 1) PREVIOUS MARKER
delay(200);
} else {
strip.setPixelColor(1, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(86, 0, 1); //D5 86 Send MIDI Note Off (D5, velocity 0, channel 1)PREVIOUS MARKER
}
//////////////////////////////////////////////////////////////////////////////
if (mcp1.digitalRead(13) == LOW) {
Serial.println("MCP1-14 LOC2");
strip.setPixelColor(0, 0, 255, 255);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-14 LOC2 90");
display.display();
strip.show();
MIDI.sendNoteOn(90, 127, 1); //A2 57 Send MIDI Note On (, velocity 127, channel 1)NEXT MARKER
delay(200);
} else {
strip.setPixelColor(0, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(90, 0, 1); //A2 57Send MIDI Note Off (, velocity 0, channel 1)NEXT MARKER
}
//////////////////////////////////////////////////////////////////////////////
if (mcp1.digitalRead(14) == LOW) {
Serial.println("MCP1-15 B4");
strip.setPixelColor(8, 0, 255, 255);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-15 B4 F4 57");
display.display();
MIDI.sendNoteOn(57, 127, 1); //A2 57 Send MIDI Note On (, velocity 127, channel 1)F4
delay(200);
} else {
strip.setPixelColor(8, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(57, 0, 1); //A2 57Send MIDI Note Off (, velocity 0, channel 1)F4
}
//////////////////////////////////////////////////////////////////////////////
if (mcp1.digitalRead(15) == LOW) {
Serial.println("MCP1-16 B3");
strip.setPixelColor(9, 0, 255, 255);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(10, 10);
display.println("MCP1-16 B3 Midi 90");
display.display();
MIDI.sendNoteOn(54, 127, 1); //F#2 54 Send MIDI Note On (, velocity 127, channel 1)F3
delay(200);
} else {
strip.setPixelColor(9, 0, 0, 0); // Turn off NeoPixel
strip.show();
MIDI.sendNoteOff(54, 0, 1); //F#2 54 Send MIDI Note Off (, velocity 0, channel 1)F3
}
}