Thanks for the reply niektb,
none of your suggestions for sw2Push actually worked. I need to change between channels and your way didnt "Go back to first case switch" so to speak... and I was still not sure about adding additional case switches to the buttons, which all i need to do is change the value from 1 to 3 for example...
I changed the digitalwrite functions to the start of the CC function, before the display message, but it wouldn't make a difference as there is no delay.
I did correct the delays in between the breaks though...
the delays were because the pads were too sensitive but I managed to figure out it was due to INPUT_PULLUP which i just needed to change the switches to LOW instead of HIGH and they aren't as sensitive anymore.
Here i've updated my code
#include <SPI.h>
#include <Wire.h>
#include <MIDI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_WIDTH 128
#define OLED_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);
//CHANGE PINS TO SUIT YOUR ARDUINO PINOUT
const int sw1Pin = A0;
const int sw2Pin = A1;
const int sw3Pin = A2;
const int sw4Pin = A3;
const int LED1 = 6; //set pin for LED 1 (CLEAN)
const int LED2 = 7; //set pin for LED 2 (GAIN 1)
const int LED3 = 8; //set pin for LED 3 (GAIN 2)
const int LED4 = 9; //set pin for LED 4 (BOOST)
const int RELAY1 = 2; //set pin for RELAY 1 (K2 Relay - Clean=HIGH)
const int RELAY2 = 3; //set pin for RELAY 2 (K4 Relay - Gain1=LOW|Gain2=HIGH)
const int RELAY3 = 4; //set pin for RELAY 3 (K7 Relay - Boost Toggle)
const int RELAY4 = 5; //set pin for RELAY 4 (K1 Relay - Plexi Toggle)
int sw1Push = 0;
int sw2Push = 0;
int sw3Push = 0;
int sw4Push = 0;
boolean sw1State = LOW;
boolean sw2State = LOW;
boolean sw3State = LOW;
boolean sw4State = LOW;
boolean sw1StateLast = LOW;
boolean sw2StateLast = LOW;
boolean sw3StateLast = LOW;
boolean sw4StateLast = LOW;
const unsigned char NaN [] PROGMEM = {
0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x03,
0x80, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x1f, 0xc0, 0x00,
0x00, 0x00, 0x03, 0xf8, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x3f, 0xe0, 0x00, 0x00, 0x00,
0x03, 0xf8, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x01, 0xf8,
0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xe8, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xe0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f,
0xe0, 0x00, 0x00, 0x01, 0xf0, 0x00, 0x1f, 0xe0, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x1f, 0xe0, 0x00,
0x00, 0x07, 0xfc, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x03, 0xfc, 0x00, 0x0f, 0x80, 0x00, 0x00, 0x03,
0xfc, 0x00, 0x0f, 0x00, 0x07, 0x00, 0x03, 0xfc, 0x00, 0x00, 0x00, 0x1f, 0xc0, 0x03, 0xfc, 0x00,
0x00, 0x04, 0x7f, 0xe0, 0x03, 0xfc, 0x00, 0x00, 0x7f, 0xff, 0xe0, 0x01, 0xfc, 0x00, 0x00, 0xff,
0xff, 0xf0, 0x00, 0xf8, 0x00, 0x00, 0xff, 0xff, 0xf8, 0x0c, 0xc0, 0x00, 0x00, 0xff, 0xff, 0xfc,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfe, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xff, 0xff, 0x83, 0xf0,
0x00, 0x00, 0xff, 0xff, 0xff, 0xc7, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xe3, 0x80, 0x00, 0x00,
0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x7f, 0xff,
0xf7, 0xf0, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xf7, 0xf0, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xf0,
0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x1f, 0xfe, 0x8f, 0xf0, 0x00, 0x00,
0x00, 0x1f, 0x80, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x03, 0x80, 0x00, 0x00
};
uint8_t midi_channel = 0;
MIDI_CREATE_DEFAULT_INSTANCE();
//MIDI CC FUNCTIONS
void midiCtrlChange(byte c, byte v){
MIDI.sendControlChange(c,v,0xB0 | midi_channel);
if (c == 80 && v >64) {
//Generic ON/OFF Switch CC MSG
//Use digitalWrite(OUTPUT,HIGH); for direct functions
}
if (c == 80 && v <=64) {
//Generic ON/OFF Switch CC MSG
//Use digitalWrite(OUTPUT,LOW); for direct functions
}
if (c == 81 && v >64) {
//Generic ON/OFF Switch CC MSG
//Use digitalWrite(OUTPUT,HIGH); for direct functions
}
if (c == 81 && v <=64) {
//Generic ON/OFF Switch CC MSG
//Use digitalWrite(OUTPUT,LOW); for direct functions
}
if (c == 82 && v >64) {
//Generic ON/OFF Switch CC MSG
//Use digitalWrite(OUTPUT,HIGH); for direct functions
}
if (c == 82 && v <=64) {
//Generic ON/OFF Switch CC MSG
//Use digitalWrite(OUTPUT,LOW); for direct functions
}
if (c == 83 && v >64) {
//Generic ON/OFF Switch CC MSG
//Use digitalWrite(OUTPUT,HIGH); for direct functions
}
if (c == 83 && v <=64) {
//Generic ON/OFF Switch CC MSG
//Use digitalWrite(OUTPUT,LOW); for direct functions
}
if (c == 85 && v >64) {
//Channel CC MSG
digitalWrite(LED1,HIGH);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(RELAY1,HIGH);
digitalWrite(RELAY2,LOW);
digitalWrite(RELAY3,LOW);
digitalWrite(RELAY4,LOW);
display.setTextSize(2);
display.setCursor(0, 20);
display.println("CLEAN ");
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(90, 50);
display.print("CC:");
display.setTextSize(1);
display.setCursor(110, 50);
display.print(c);
display.display();
}
if (c == 85 && v <=64) {
//Channel CC MSG
digitalWrite(LED1,LOW);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,LOW);
digitalWrite(RELAY1,LOW);
digitalWrite(RELAY2,LOW);
}
if (c == 86 && v >64) {
//Channel CC MSG
digitalWrite(LED1,LOW);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,LOW);
digitalWrite(RELAY1,LOW);
digitalWrite(RELAY2,LOW);
display.setTextSize(2);
display.setCursor(0, 20);
display.println("GAIN 1 ");
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(90, 50);
display.print("CC:");
display.setTextSize(1);
display.setCursor(110, 50);
display.print(c);
display.display();
}
if (c == 86 && v <=64) {
//Channel CC MSG
digitalWrite(LED1,HIGH);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(RELAY1,HIGH);
digitalWrite(RELAY2,LOW);
}
if (c == 87 && v >64) {
//Channel CC MSG
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,HIGH);
digitalWrite(RELAY1,LOW);
digitalWrite(RELAY2,HIGH);
display.setTextSize(2);
display.setCursor(0, 20);
display.println("GAIN 2 ");
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(90, 50);
display.print("CC:");
display.setTextSize(1);
display.setCursor(110, 50);
display.print(c);
display.display();
}
if (c == 87 && v <=64) {
//Channel CC MSG
digitalWrite(LED1,LOW);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,LOW);
digitalWrite(RELAY1,LOW);
digitalWrite(RELAY2,LOW);
}
if (c == 88 && v >64) {
//Channel CC MSG
digitalWrite(LED4,HIGH);
digitalWrite(RELAY3,HIGH);
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(0, 50);
display.print("BOOST: ");
display.setTextSize(1);
display.setCursor(40, 50);
display.print("ON ");
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(90, 50);
display.print("CC:");
display.setTextSize(1);
display.setCursor(110, 50);
display.print(c);
display.display();
}
if (c == 88 && v <=64) {
//Channel CC MSG
digitalWrite(LED4,LOW);
digitalWrite(RELAY3,LOW);
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(0, 50);
display.print("BOOST: ");
display.setTextSize(1);
display.setCursor(40, 50);
display.print("OFF");
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(90, 50);
display.print("CC:");
display.setTextSize(1);
display.setCursor(110, 50);
display.print(c);
display.display();
}
if (c == 89 && v >64) {
//Toggle CC MSG
digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
digitalWrite(RELAY1,LOW);
digitalWrite(RELAY4,HIGH);
display.setTextSize(2);
display.setCursor(0, 20);
display.println("PLEXI ");
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(90, 50);
display.print("CC:");
display.setTextSize(1);
display.setCursor(110, 50);
display.print(c);
display.display();
}
if (c == 89 && v <=64) {
//Toggle CC MSG
digitalWrite(LED2,LOW);
digitalWrite(RELAY4,LOW);
}
if (c == 90 && v >64) {
//Toggle CC MSG
//Use digitalWrite(OUTPUT,HIGH); for direct functions
}
if (c == 90 && v <=64) {
//Toggle CC MSG
//Use digitalWrite(OUTPUT,LOW); for direct functions
}
if (c == 91 && v >64) {
//Reverb Volume CC MSG
//Use digitalWrite(OUTPUT,HIGH); for direct functions
}
if (c == 91 && v <=64) {
//Reverb Volume CC MSG
//Use digitalWrite(OUTPUT,LOW); for direct functions
}
if (c == 92 && v >64) {
//Tremelo Volume CC MSG
//Use digitalWrite(OUTPUT,HIGH); for direct functions
}
if (c == 92 && v <=64) {
//Tremelo Volume CC MSG
//Use digitalWrite(OUTPUT,LOW); for direct functions
}
if (c == 102) {
//EEPROM Reset CC MSG
//Use digitalWrite(OUTPUT,HIGH); for direct functions
}
if (c == 103) {
//Set MIDI Channel CC MSG
//Use digitalWrite(OUTPUT,HIGH); for direct functions
}
if (c == 104) {
//Store Preset CC MSG
//Use digitalWrite(OUTPUT,HIGH); for direct functions
}
if (c == 105) {
//MUTE Function Switch CC MSG
//Use digitalWrite(OUTPUT,LOW); for direct functions
}
}
void setup() {
//INITIATE INPUT & OUTPUTS
pinMode(sw1Pin, INPUT_PULLUP);
pinMode(sw2Pin, INPUT_PULLUP);
pinMode(sw3Pin, INPUT_PULLUP);
pinMode(sw4Pin, INPUT_PULLUP);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
// INITIATE CLEAN CHANNEL
digitalWrite(LED1,HIGH);
digitalWrite(RELAY1,HIGH);
// INITIATE MIDI
Serial.begin(9600);
MIDI.begin(MIDI_CHANNEL_OMNI);
// INITIATE DISPLAY SPLASHSCREEN
Wire.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(0, 0);
display.println(" SIRIUS AMPLIFICATION ");
display.drawBitmap(40, 15, NaN, 50, 50, WHITE);
display.display();
delay(5000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(0, 0);
display.println(" SIRIUS AMPLIFICATION ");
display.display();
midiCtrlChange(88,0);
midiCtrlChange(85,127);
}
void loop() {
MIDI.read();
//SWITCH 1 FUNCTIONS
sw1State = digitalRead(sw1Pin);
if (sw1State != sw1StateLast) {
if (sw1State == LOW){
sw1Push++;
if (sw1Push > 1){sw1Push = 0;}
switch (sw1Push)
{
case 0:
midiCtrlChange(89,127);
break;
case 1:
midiCtrlChange(88,0);
midiCtrlChange(85,127);
break;
}
}
delay(200);
sw1StateLast = sw1State;
}
//SWITCH 2 FUNCTIONS
sw2State = digitalRead(sw2Pin);
if (sw2State != sw2StateLast) {
if (sw2State == LOW){
sw2Push++;
if (sw2Push > 1){sw2Push = 0;}
switch (sw2Push)
{
case 0:
midiCtrlChange(87,127);
break;
case 1:
midiCtrlChange(86,127);
break;
}
}
sw2StateLast = sw2State;
delay(200);
}
//SWITCH 3 FUNCTIONS
sw3State = digitalRead(sw3Pin);
if (sw3State != sw3StateLast) {
if (sw3State == LOW){
sw3Push++;
if (sw3Push > 1){sw3Push = 0;}
switch (sw3Push)
{
case 0:
midiCtrlChange(88,0);
break;
case 1:
midiCtrlChange(88,127);
break;
}
}
delay(200);
sw3StateLast = sw3State;
}
//SWITCH 4 FUNCTIONS
sw4State = digitalRead(sw4Pin);
if (sw4State != sw4StateLast) {
if (sw4State == LOW){
sw4Push++;
if (sw4Push > 1){sw4Push = 0;}
switch (sw4Push)
{
case 1:
midiCtrlChange(89,0);
midiCtrlChange(85,127);
break;
case 0:
midiCtrlChange(89,127);
break;
}
}
delay(200);
sw4StateLast = sw4State;
}
}