Sorry
Here is the full code
/******************
*
* SETUP
*
*******************/
#include <MIDI.h>
#include "Controller.h"
#include <FastLED.h>
#define DATA_PIN 12
#define NUM_LEDS 8
#define LED_TYPE WS2811
MIDI_CREATE_DEFAULT_INSTANCE();
byte NUMBER_BUTTONS = 8;
byte NUMBER_POTS = 1;
byte NUMBER_MUX_BUTTONS = 0;
byte NUMBER_MUX_POTS = 0;
Pot PO1(A0, 0, 8, 2);
Pot *POTS[] {&PO1};
Button BU1(7, 1, 0, 2, 5 );
Button BU2(6, 1, 1, 2, 5 );
Button BU3(5, 1, 2, 2, 5 );
Button BU4(4, 1, 3, 2, 5 );
Button BU5(11, 1, 4, 2, 5 );
Button BU6(10, 1, 5, 2, 5 );
Button BU7(9, 1, 6, 2, 5 );
Button BU8(8, 1, 7, 2, 5 );
Button *BUTTONS[] {&BU1, &BU2, &BU3, &BU4, &BU5, &BU6, &BU7, &BU8};
Button *MUXBUTTONS[] {};
Pot *MUXPOTS[] {};
CRGB leds[NUM_LEDS];
void setstrips() {
leds[0] = CRGB( 50, 0, 0);
FastLED.show();
delay(150);
leds[1] = CRGB( 50, 25, 0);
FastLED.show();
delay(150);
leds[2] = CRGB( 50, 50, 0);
FastLED.show();
delay(150);
leds[3] = CRGB( 0, 50, 0);
FastLED.show();
delay(150);
leds[4] = CRGB( 0, 50, 50);
FastLED.show();
delay(150);
leds[5] = CRGB( 0, 0, 50);
FastLED.show();
delay(150);
leds[6] = CRGB( 25, 0, 50);
FastLED.show();
delay(150);
leds[7] = CRGB( 50, 0, 50);
FastLED.show();
delay(150);
}
void setup() {
MIDI.begin(MIDI_CHANNEL_OMNI);
MIDI.setHandleControlChange(MIDIinput);
MIDI.turnThruOff();
FastLED.addLeds<WS2811,DATA_PIN, RGB>(leds, NUM_LEDS);
setstrips();
}
void loop() {
if (NUMBER_BUTTONS != 0) updateButtons();
if (NUMBER_POTS != 0) updatePots();
if (NUMBER_MUX_BUTTONS != 0) updateMuxButtons();
if (NUMBER_MUX_POTS != 0) updateMuxPots();
MIDI.read();
FastLED.show();
}
void MIDIinput(byte channel, byte number, byte value) {
if (number<8) {
if (value > 64) {
leds[number] *=4;
}else{
leds[number] /=4;
}
}}
void updateButtons() {
// Cycle through Button array
for (int i = 0; i < NUMBER_BUTTONS; i = i + 1) {
byte message = BUTTONS[i]->getValue();
// Button is pressed
if (message == 0) {
switch (BUTTONS[i]->Bcommand) {
case 0: //Note
MIDI.sendNoteOn(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
break;
case 1: //CC
MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
break;
case 2: //Toggle
if (BUTTONS[i]->Btoggle == 0) {
MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
BUTTONS[i]->Btoggle = 1;
}
else if (BUTTONS[i]->Btoggle == 1) {
MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
BUTTONS[i]->Btoggle = 0;
}
break;
}
}
// Button is not pressed
if (message == 1) {
switch (BUTTONS[i]->Bcommand) {
case 0:
MIDI.sendNoteOff(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
break;
case 1:
MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
break;
}
}
}
}
//*******************************************************************
void updateMuxButtons() {
// Cycle through Mux Button array
for (int i = 0; i < NUMBER_MUX_BUTTONS; i = i + 1) {
MUXBUTTONS[i]->muxUpdate();
byte message = MUXBUTTONS[i]->getValue();
// Button is pressed
if (message == 0) {
switch (MUXBUTTONS[i]->Bcommand) {
case 0: //Note
MIDI.sendNoteOn(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
break;
case 1: //CC
MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
break;
case 2: //Toggle
if (MUXBUTTONS[i]->Btoggle == 0) {
MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
MUXBUTTONS[i]->Btoggle = 1;
}
else if (MUXBUTTONS[i]->Btoggle == 1) {
MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
MUXBUTTONS[i]->Btoggle = 0;
}
break;
}
}
// Button is not pressed
if (message == 1) {
switch (MUXBUTTONS[i]->Bcommand) {
case 0:
MIDI.sendNoteOff(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
break;
case 1:
MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
break;
}
}
}
}
//***********************************************************************
void updatePots() {
for (int i = 0; i < NUMBER_POTS; i = i + 1) {
byte potmessage = POTS[i]->getValue();
if (potmessage != 255) MIDI.sendControlChange(POTS[i]->Pcontrol, potmessage, POTS[i]->Pchannel);
}
}
//***********************************************************************
void updateMuxPots() {
for (int i = 0; i < NUMBER_MUX_POTS; i = i + 1) {
MUXPOTS[i]->muxUpdate();
byte potmessage = MUXPOTS[i]->getValue();
if (potmessage != 255) MIDI.sendControlChange(MUXPOTS[i]->Pcontrol, potmessage, MUXPOTS[i]->Pchannel);
}
}