News:

SMF for DIYStompboxes.com!

Main Menu

Arduino MIDI Switcher

Started by potul, November 04, 2015, 01:21:57 PM

Previous topic - Next topic

ElectricDruid

Quote from: potul on March 25, 2022, 05:14:08 AM
I agree with niektb, what I would develop is something to put between your TRS footswitches and the amp. Basically using the footswitches as an input to the arduino, and then sending the commands from the arduino to the amp via TRS emulating what the footswitches do.
This is going to be much easier to manage if you want both footswitches and MIDI to work at the same time.

I agree too, BUT ONLY in the case where the footswitches do something other than a momentary short-to-ground. For that particular situation, it's dead easy to have the footswitches and the MIDI-controlled transistors in parallel. You press a footswitch, it switches. You send a MIDI signal, a transistor goes on, it switches.

BUT, as I said, that does depend on the momentary, non-latching character of the footswitches, and that that's what the amp is expecting.

Overall, the footswitches-go-to-processor-then-processor-controls-amp set up is much more versatile, since it can deal with latching/momentary and normal/inverted polarity just by changing firmware.

HTH

T Wilcox

Quote from: niektb on March 25, 2022, 04:19:42 AM
Actually what I would do, is connect the TRS Footswitches to the microcontroller, you don't have to work out an ORing/ANDing mechanism :)
I don't think there is readily working code in this thread but sounds quite doable to roll it yourself :)
And I think you it doesnt matter if the switches are momentary or latching since you can work that out in software :)

Thank you for your feedback!
I've done just a couple very simple arduino programs over a year ago so was hoping to grab some existing code that is close and then edit it to my needs. I have no problem taking the time to re-learn it though so I will spend some time getting familiar again.
My concern with the latching toggles and footswitches is that the toggle or footswitch positions wont match the state of the relays(iow if the toggle is in the up/on position then you send MIDI command to turn it off the toggle is still up. All my other MIDI controlled devices do use momentary switches and it would be easy enough to swap them for momentary

T Wilcox

Quote from: potul on March 25, 2022, 05:14:08 AM
I agree with niektb, what I would develop is something to put between your TRS footswitches and the amp. Basically using the footswitches as an input to the arduino, and then sending the commands from the arduino to the amp via TRS emulating what the footswitches do.
This is going to be much easier to manage if you want both footswitches and MIDI to work at the same time.
Thank you for your reply!
Yes, indeed it would be ideal for the toggles, footswitch and MIDI to all work at the same time
So basically I would want the toggles and footswitches (they are parallel but toggles are disabled by the stereo jack when 1/4" plug is inserted) to connect straight to the arduino as digital inputs?
Then connect the return leg of the relay circuit to the outputs which will send that point to ground when activated?
If thats correct, then I just need to wrap my head around the programming which will take me a bit
Thanks again!

T Wilcox

Quote from: ElectricDruid on March 25, 2022, 04:55:15 PM
Quote from: potul on March 25, 2022, 05:14:08 AM
I agree with niektb, what I would develop is something to put between your TRS footswitches and the amp. Basically using the footswitches as an input to the arduino, and then sending the commands from the arduino to the amp via TRS emulating what the footswitches do.
This is going to be much easier to manage if you want both footswitches and MIDI to work at the same time.

I agree too, BUT ONLY in the case where the footswitches do something other than a momentary short-to-ground. For that particular situation, it's dead easy to have the footswitches and the MIDI-controlled transistors in parallel. You press a footswitch, it switches. You send a MIDI signal, a transistor goes on, it switches.

BUT, as I said, that does depend on the momentary, non-latching character of the footswitches, and that that's what the amp is expecting.

Overall, the footswitches-go-to-processor-then-processor-controls-amp set up is much more versatile, since it can deal with latching/momentary and normal/inverted polarity just by changing firmware.

HTH
Thank you! The preamp currently has latching but it would not be hard to swap them out for momentary and it would make more sense now with MIDI and presets so I'll try that first.
Now that I have a better idea of what how to re-design the hardware I will breadboard this so I can start messing with the software before committing a new pcb design
Thanks again for your input!

acatlow

#64
I made a diagram over at https://wokwi.com/projects/330329978730185299

Basically its a 4 button footswitch, not sure if midi works but ive tested the circuit and with momuntary buttons its working fine, but I have only tried with the 8 relay board connecting IN pins to LED pins, I have yet to test with normal DPDT relays.

I made a test bench so I could test it out yesterday which i've added pictures

Here is the code to make it more simple, would love to get feedback also as this is my first sketch with arduino

Thanks Guys



#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

MIDI_CREATE_INSTANCE(HardwareSerial,Serial, midiOut);

int ledState = HIGH;         // the current state of the output pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers

void setup() {

Serial.begin(9600);      // INITIALISE SERIAL
pinMode(2,INPUT_PULLUP); //CLEAN CHANNEL TOGGLE
pinMode(3,INPUT_PULLUP); //CRUNCH CHANNEL TOGGLE
pinMode(4,INPUT_PULLUP); //LEAD CHANNEL TOGGLE
pinMode(5,INPUT_PULLUP); //BOOST CHANNEL TOGGLE
pinMode(6,OUTPUT); // D6,
pinMode(7,OUTPUT); // D7,
pinMode(8,OUTPUT); // D8,
pinMode(9,OUTPUT); // D9,

//Initial Output States. Init to Clean Mode
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(9, ledState);
}

void loop() {
  delay(10); //wait for 10 milliseconds for states to settle
  int reading = digitalRead(5);

  if (reading != lastButtonState) {
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (reading != buttonState) {
      buttonState = reading;
      if (buttonState == HIGH) {
        ledState = !ledState;
      }
    }
  }
  digitalWrite(9, ledState);
  lastButtonState = reading;
 
//Clean Mode
if(!digitalRead(2)){
  // LEDS
  digitalWrite(6,HIGH);
  digitalWrite(7,LOW);
  digitalWrite(8,LOW);
  digitalWrite(9,LOW);
  midiOut.sendControlChange(85,127,1);
  }

//Crunch Mode
if(!digitalRead(3)){
  // LEDS
  digitalWrite(6,LOW);
  digitalWrite(7,HIGH);
  digitalWrite(8,LOW);
  digitalWrite(9,LOW);
  midiOut.sendControlChange(86,127,1);
  }

//Lead Mode
if(!digitalRead(4)){
  // LEDS
  digitalWrite(6,LOW);
  digitalWrite(7,LOW);
  digitalWrite(8,HIGH);
  digitalWrite(9,LOW);
  midiOut.sendControlChange(87,127,1);
  }


}





Alex Catlow

Sirius Amplification
https://siriusamplification.com.au

pruttelherrie

Quote from: acatlow on April 29, 2022, 10:44:17 PM

Here is the code to make it more simple, would love to get feedback also as this is my first sketch with arduino


#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial,Serial, midiOut);

[snip]
void setup() {
Serial.begin(9600);      // INITIALISE SERIAL



If you're using MIDI on an AVR with one HW serial you can't use the standard Serial at the same time, it's either/or.

Also, you're only debouncing pin 5, not the other inputs? Probably no problem right now but you might see a flurry of CC's coming past.
Might be that I don't understand your switches, pin 5 is the toggle (for boost) and the others are momentary pushbuttons?

potul

Yep, the Serial begin sentence should be removed, the UART will already be initialized by the MIDI instance

On the other hand... you are doing debouncing on pin 5 only, and it's not clear to me what this button does.

acatlow

#67
oh apologies, i should update the code already, I changed this to midi create default instance without any custom midiout or serial

but i want to edit the code to be more like this

clean channel 1 toggle (k2 relay 1 = high, relay 2 = low) switches green led
gain channels 2/3 toggle (k4 relay 1 = low, relay 2 = low / relay 1 = low , relay 2 = high)  switches between bicolour blue red led)
boost channel toggle (k7 relay, can turn on or off independently across all channels)

anybody can help me with this?



#include <MIDI.h>
#include <EEPROM.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

MIDI_CREATE_DEFAULT_INSTANCE();

byte inChannel;

int ledState = HIGH;         // the current state of the output pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers

void handleProgramChange(byte channel, byte number)
{
    // Can set functions for PC messages here
}

void handleControlChange(byte channel, byte number, byte value){
   
    if (number == 85 && value <=64) {
      digitalWrite(8, HIGH);
    }
    else {
      digitalWrite(8, LOW);
    }
   
    if (number == 86 && value <=64) {
      digitalWrite(9, HIGH);
    }
    else {
      digitalWrite(9, LOW);
    }
   
    if (number == 87 && value <=64) {
      digitalWrite(10, HIGH);
    }
    else {
      digitalWrite(10, LOW);
    }
   
    if (number == 88 && value <=64) {
      digitalWrite(11, HIGH);
    }
    else {
      digitalWrite(11, LOW);
    }
}
void setup() {
MIDI.begin (MIDI_CHANNEL_OMNI);
pinMode(2,INPUT_PULLUP); //CLEAN CHANNEL TOGGLE
pinMode(3,INPUT_PULLUP); //GAIN CHANNEL TOGGLE
pinMode(4,INPUT_PULLUP); //BOOST CHANNEL TOGGLE
pinMode(5,OUTPUT); // D5 - K2 RELAY
pinMode(6,OUTPUT); // D6 - K4 RELAY
pinMode(7,OUTPUT); // D7 - K7 RELAY
pinMode(8,OUTPUT); // D8 - LED 1
pinMode(9,OUTPUT); // D9 - LED 2
pinMode(10,OUTPUT); // D10 - LED 3
pinMode(10,OUTPUT); // D11 - LED 4

}
void loop() {
  delay(5);
 
//Clean Mode
if(!digitalRead(2)){
  // LEDS
  digitalWrite(8,HIGH);
  digitalWrite(9,LOW);
  digitalWrite(10,LOW);
  }

//Gain Mode
if(!digitalRead(3)){
  // LEDS
  digitalWrite(8,LOW);
  digitalWrite(9,HIGH);
  digitalWrite(10, ledState);
  }

//BOOST ON/OFF
  int reading = digitalRead(4);
  if (reading != lastButtonState) {
    lastDebounceTime = millis();
  }
  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (reading != buttonState) {
      buttonState = reading;
      if (buttonState == HIGH) {
        ledState = !ledState;
      }
    }
  }
  digitalWrite(10, ledState);
  lastButtonState = reading;
}

Alex Catlow

Sirius Amplification
https://siriusamplification.com.au

acatlow

Hi all,

Thought I'd share with you all that I managed to finish my version which I've currently fit into a Peavey 2 button footswitch, that I drilled out the middle hole to add the third monument switch.

I emailed potul, who confirmed with me that my issue wasn't in the code itself but the wokwi diagram code, so thanks potul for the confirmation.

the next thing I will be doing is adding the oled display menu to show visually what channel is currently active etc

here is the simulation of the code

https://wokwi.com/projects/330813583919153748



#include <OneButton.h>
#include <EEPROM.h>
#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>
#include <SSD1306Ascii.h>
#include <SSD1306AsciiWire.h>

#define LED1 8   //set pin for LED 1 (CLEAN)
#define LED2 9   //set pin for LED 2 (GAIN 1)
#define LED3 10  //set pin for LED 3 (GAIN 2)
#define LED4 11  //set pin for LED 4 (BOOST)
#define RELAY1 5 //set pin for RELAY 1 (K2 Relay - Clean=HIGH)
#define RELAY2 6 //set pin for RELAY 2 (K4 Relay - Gain1=LOW|Gain2=HIGH)
#define RELAY3 7 //set pin for RELAY 3 (K7 Relay - Boost Toggle)
#define SW1 2    //set pin for SWITCH 1
#define SW2 3    //set pin for SWITCH 2
#define SW3 4    //set pin for SWITCH 3

// OLED Display 128x64
#define I2C_ADDRESS 0x3C
#define RST_PIN -1
SSD1306AsciiWire oled;

MIDI_CREATE_DEFAULT_INSTANCE();

byte curr_program;    //Current PC Value
byte curr_change;     //Current CC Value

OneButton button1(SW1, true);
OneButton button2(SW2, true);
OneButton button3(SW3, true);

void handleNoteOn(byte channel, byte pitch, byte velocity)
{
}

void handleNoteOff(byte channel, byte pitch, byte velocity)
{
}

void handleProgramChange(byte channel, byte number)
{
  byte value;
  curr_program=number; //stores the PC number for later
  value=EEPROM.read(number);
  //Activate LED1
  if (getBit(value,1))
   {
    digitalWrite(LED1,HIGH);
   }
   else
   {
    digitalWrite(LED1,LOW);
   }
  //Activate LED2
  if (getBit(value,2))
   {
    digitalWrite(LED2,HIGH);
   }
   else
   {
    digitalWrite(LED2,LOW);
   }
  //Activate LED3
  if (getBit(value,3))
   {
    digitalWrite(LED3,HIGH);
   }
   else
   {
    digitalWrite(LED3,LOW);
   }
  //Activate LED4
  if (getBit(value,4))
   {
    digitalWrite(LED4,HIGH);
   }
   else
   {
    digitalWrite(LED4,LOW);
   }
}
void handleControlChange(byte channel, byte number, byte value){
  if (number == 85 && value <=64) {
    digitalWrite(LED1,HIGH);
  }
  if (number == 85 && value >64) {
    digitalWrite(LED1,LOW);
  }
  if (number == 86 && value <=64) {
    digitalWrite(LED2,HIGH);
  }
  if (number == 86 && value >64) {
    digitalWrite(LED2,LOW);
  }
  if (number == 87 && value <=64) {
    digitalWrite(LED3,HIGH);
  }
  if (number == 87 && value >64) {
    digitalWrite(LED3,LOW);
  }
  if (number == 88 && value <=64) {
    digitalWrite(LED4,HIGH);
  }
  if (number == 88 && value >64) {
    digitalWrite(LED4,LOW);
  }
}

void click1() {
  //Toggle Relay 1
  byte value;
  value=digitalRead(LED1);
  value++;
    if (getBit(value,1))
   {
     digitalWrite(LED1,HIGH);
     digitalWrite(LED3,LOW);
     digitalWrite(RELAY1,HIGH);
     MIDI.sendControlChange(1,85,127);
   }
   else
   {
      digitalWrite(LED1,LOW);
      digitalWrite(LED3,LOW);
      digitalWrite(RELAY1,LOW);
   }
  //Activate Relay 2
  if (getBit(value,2))
   {
     digitalWrite(LED2,HIGH);
     digitalWrite(LED3,LOW);
     digitalWrite(RELAY1,LOW);
     MIDI.sendControlChange(1,86,127);
   }
   else
   {
      digitalWrite(LED2,LOW);
      digitalWrite(LED3,LOW);
      digitalWrite(RELAY1,HIGH);
   }
} // click1

void click2() {
  //Toggle Relay 2
  byte value;
  value=digitalRead(LED2);
  value++;
  if (getBit(value,1))
   {
     digitalWrite(LED1,LOW);
     digitalWrite(LED2,HIGH);
     digitalWrite(RELAY2,LOW);
   }
   else
   {
      digitalWrite(LED1,LOW);
      digitalWrite(LED2,LOW);
      digitalWrite(RELAY2,HIGH);
   }
  if (getBit(value,2))
   {
     digitalWrite(LED1,LOW);
     digitalWrite(LED3,HIGH);
     digitalWrite(RELAY2,HIGH);
     MIDI.sendControlChange(1,87,127);
   }
   else
   {
      digitalWrite(LED1,LOW);
      digitalWrite(LED3,LOW);
      digitalWrite(RELAY2,LOW);
   }
} // click2

void click3() {
  //Toggle Relay 3
  byte value;
  value=digitalRead(LED4);
  value++;
  if (getBit(value,1))
   {
     digitalWrite(LED4,HIGH);
     MIDI.sendControlChange(1,88,127);
   }
   else
   {
      digitalWrite(LED4,LOW);
      MIDI.sendControlChange(1,88,0);
   }
} // click3

void doubleclick1() {}

void longPressStart1() {
  //save preset
  byte value=1;
  if (digitalRead(LED1))
  {
    setBit(value,1);
  }
  if (digitalRead(LED2))
  {
    setBit(value,2);
  }
  if (digitalRead(LED3))
  {
    setBit(value,3);
  }
  if (digitalRead(LED4))
  {
    setBit(value,4);
  }
  EEPROM.write(curr_program,value);
}

void longPress1() {}

void longPressStop1() {}

void setup()
{
    pinMode(LED1, OUTPUT);
    pinMode(LED2, OUTPUT);
    pinMode(LED3, OUTPUT);
    pinMode(LED4, OUTPUT);
    pinMode(RELAY1, OUTPUT);
    pinMode(RELAY2, OUTPUT);
    pinMode(RELAY3, OUTPUT);
    pinMode(SW1, INPUT_PULLUP);
    pinMode(SW2, INPUT_PULLUP);
    pinMode(SW3, INPUT_PULLUP);

    for (int i=0;i<128;i++)
    {
      EEPROM.write(i,i);
    }
   
    //Initial Output States. Init to Clean Mode
    digitalWrite(8,HIGH);
    digitalWrite(9,LOW);
    digitalWrite(10,LOW);

    button1.attachClick(click1);
    button2.attachClick(click2);
    button3.attachClick(click3);

    button1.attachDoubleClick(doubleclick1);
    button1.attachLongPressStart(longPressStart1);
    button1.attachLongPressStop(longPressStop1);
    button1.attachDuringLongPress(longPress1);
   
    MIDI.setHandleNoteOn(handleNoteOn);
    MIDI.setHandleNoteOff(handleNoteOff);
    MIDI.setHandleProgramChange(handleProgramChange);
    MIDI.setHandleControlChange(handleControlChange);

    // Initiate MIDI
    MIDI.begin(MIDI_CHANNEL_OMNI);
}
void loop()
{
    MIDI.read();

    // Call button tick to check button status
    button1.tick();
    button2.tick();
    button3.tick();
}

byte setBit(byte &store, byte bitn) { //bit 1 is right-most
      store = (1 << (bitn - 1)); //set bit 5 to '1'.
}

byte clearBit(byte &store, byte bitn) {
      store &= !(1 << (bitn - 1));
}

bool getBit(byte store, byte bitn) {
      byte b = (1 << (bitn - 1));
      return (store & b);
}


Alex Catlow

Sirius Amplification
https://siriusamplification.com.au

acatlow

#69
Back again,

Just to make it more exciting, I wrote up something different, adding in OLED display.
If you get an error in Arduino IDE, add the library "Adafruit BusIO"

you can simulate the code here --> https://wokwi.com/projects/331591906805940818




#include <SPI.h>
#include <Wire.h>
#include <MIDI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

const int sw1Pin = 2;
const int sw2Pin = 3;
const int sw3Pin = 4;
const int sw4Pin = A0;
const int LED1 = 8;  //set pin for LED 1 (CLEAN)
const int LED2 = 9;   //set pin for LED 2 (GAIN 1)
const int LED3 = 10;  //set pin for LED 3 (GAIN 2)
const int LED4 = 11;  //set pin for LED 4 (BOOST)
const int LED5 = 13;  //set pin for LED 5 (PLEXI)
const int RELAY1 = 5; //set pin for RELAY 1 (K2 Relay - Clean=HIGH)
const int RELAY2 = 6; //set pin for RELAY 2 (K4 Relay - Gain1=LOW|Gain2=HIGH)
const int RELAY3 = 7; //set pin for RELAY 3 (K7 Relay - Boost Toggle)
const int RELAY4 = 12; //set pin for RELAY 4 (K3 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;

//DEFINITIONS
#define OLED_WIDTH 128
#define OLED_HEIGHT 64
#define OLED_ADDR   0x3C
Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);

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();

void midiCtrlChange(byte c, byte v){
  Serial.write(0xB0 | midi_channel); // CC message
  Serial.write(c); // number
  Serial.write(v); // value

  if (c == 85 && v >64) {
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE, BLACK);
    display.setCursor(0, 0);
    display.println(" SIRIUS AMPLIFICATION");
    display.setTextSize(2);
    display.setCursor(0, 20);
    display.println("CLEAN ");
    display.display();
    digitalWrite(LED1,HIGH);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,LOW);
    digitalWrite(LED4,LOW);
    digitalWrite(RELAY1,HIGH);
    digitalWrite(RELAY2,LOW);
    digitalWrite(RELAY3,LOW);
  }
  if (c == 85 && v <=64) {
    display.setTextSize(1);
    display.setTextColor(WHITE, BLACK);
    display.setCursor(0, 0);
    display.println(" SIRIUS AMPLIFICATION");
    display.setTextSize(2);
    display.setCursor(0, 20);
    display.println("GAIN 1");
    display.display();
  digitalWrite(LED1,LOW);
    digitalWrite(LED2,HIGH);
    digitalWrite(LED3,LOW);
    digitalWrite(RELAY1,LOW);
    digitalWrite(RELAY2,LOW);
  }
  if (c == 86 && v >64) {
    display.setTextSize(1);
    display.setTextColor(WHITE, BLACK);
    display.setCursor(0, 0);
    display.println(" SIRIUS AMPLIFICATION");
    display.setTextSize(2);
    display.setCursor(0, 20);
    display.println("GAIN 1");
    display.display();
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,HIGH);
    digitalWrite(LED3,LOW);
    digitalWrite(RELAY1,LOW);
    digitalWrite(RELAY2,LOW);
  }
  if (c == 86 && v <=64) {
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE, BLACK);
    display.setCursor(0, 0);
    display.println(" SIRIUS AMPLIFICATION");
    display.setTextSize(2);
    display.setCursor(0, 20);
    display.println("CLEAN ");
    display.display();
    digitalWrite(LED1,HIGH);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,LOW);
    digitalWrite(RELAY1,HIGH);
    digitalWrite(RELAY2,LOW);
  }
  if (c == 87 && v >64) {
    display.setTextSize(1);
    display.setTextColor(WHITE, BLACK);
    display.setCursor(0, 0);
    display.println(" SIRIUS AMPLIFICATION");
    display.setTextSize(2);
    display.setCursor(0, 20);
    display.println("GAIN 2");
    display.display();
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,HIGH);
    digitalWrite(RELAY1,LOW);
    digitalWrite(RELAY2,HIGH);
  }
  if (c == 87 && v <=64) {
    display.setTextSize(1);
    display.setTextColor(WHITE, BLACK);
    display.setCursor(0, 0);
    display.println(" SIRIUS AMPLIFICATION");
    display.setTextSize(2);
    display.setCursor(0, 20);
    display.println("GAIN 1");
    display.display();
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,HIGH);
    digitalWrite(LED3,LOW);
    digitalWrite(RELAY1,LOW);
    digitalWrite(RELAY2,LOW);
  }
  if (c == 88 && v >64) {
    display.setTextSize(1);
    display.setTextColor(WHITE, BLACK);
    display.setCursor(0, 45);
    display.print("BOOST: ");
    display.setTextSize(1);
    display.setCursor(45, 45);
    display.print("ON ");
    display.display();
    digitalWrite(LED4,HIGH);
    digitalWrite(RELAY3,HIGH);
  }
  if (c == 88 && v <=64) {
    display.setTextSize(1);
    display.setTextColor(WHITE, BLACK);
    display.setCursor(0, 45);
    display.print("BOOST: ");
    display.setTextSize(1);
    display.setCursor(45, 45);
    display.print("OFF");
    display.display();
    digitalWrite(LED4,LOW);
    digitalWrite(RELAY3,LOW);
  }
  if (c == 89 && v >64) {
    display.setTextSize(1);
    display.setTextColor(WHITE, BLACK);
    display.setCursor(0, 55);
    display.print("PLEXI: ");
    display.setTextSize(1);
    display.setCursor(45, 55);
    display.print("ON ");
    display.display();
    digitalWrite(LED5,HIGH);
    digitalWrite(RELAY4,HIGH);
  }
  if (c == 89 && v <=64) {
    display.setTextSize(1);
    display.setTextColor(WHITE, BLACK);
    display.setCursor(0, 55);
    display.print("PLEXI: ");
    display.setTextSize(1);
    display.setCursor(45, 55);
    display.print("OFF");
    display.display();
    digitalWrite(LED5,LOW);
    digitalWrite(RELAY4,LOW);
  }
}

void setup() {
  pinMode(sw1Pin, INPUT);
  pinMode(sw2Pin, INPUT);
  pinMode(sw3Pin, INPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(RELAY1, OUTPUT);
  pinMode(RELAY2, OUTPUT);
  pinMode(RELAY3, OUTPUT);

  // Initiate MIDI
  MIDI.begin(MIDI_CHANNEL_OMNI);

// INITIATE DISPLAY SPLASHSCREEN
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  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);
  midiCtrlChange(85,127);
}

void loop() {

MIDI.read();

// read the state of the pushbutton value:
  sw1State = digitalRead(sw1Pin);
  if (sw1State != sw1StateLast) {
    if (sw1State == HIGH){
      sw1Push++;
      if (sw1Push > 1){sw1Push = 0;}
      switch (sw1Push)
      {
        case 1:
          midiCtrlChange(85,127);
        break;
        delay(200);
        case 0:
          midiCtrlChange(86,127);
        break;
        delay(200);
      }
    }
    sw1StateLast = sw1State;
    delay(200);
  }

sw2State = digitalRead(sw2Pin);
if (sw2State != sw2StateLast) {
    if (sw2State == HIGH){
      sw2Push++;
      if (sw2Push > 1){sw2Push = 0;}
      switch (sw2Push)
      {
        case 1:
          midiCtrlChange(87,127);
        break;
        delay(200);
        case 0:
          midiCtrlChange(86,127);
        break;
        delay(200);
      }
    }
    sw2StateLast = sw2State;
    delay(200);
  }

sw3State = digitalRead(sw3Pin);
if (sw3State != sw3StateLast) {
    if (sw3State == HIGH){
      sw3Push++;
      if (sw3Push > 1){sw3Push = 0;}
      switch (sw3Push)
      {
        case 0:
          midiCtrlChange(88,0);
        break;
        delay(200);
        case 1:
          midiCtrlChange(88,127);
        break;
        delay(200);
      }
    }
    sw3StateLast = sw3State;
    delay(200);
  }

sw4State = digitalRead(sw4Pin);
if (sw4State != sw4StateLast) {
    if (sw4State == HIGH){
      sw4Push++;
      if (sw4Push > 1){sw4Push = 0;}
      switch (sw4Push)
      {
        case 0:
          midiCtrlChange(89,0);
        break;
        delay(200);
        case 1:
          midiCtrlChange(89,127);
        break;
        delay(200);
      }
    }
    sw4StateLast = sw4State;
    delay(200);
  }
}

Alex Catlow

Sirius Amplification
https://siriusamplification.com.au

potul

Nice,

just a comment: you are using the MIDI library but not using the sendControlChange() function and instead you are accessing Serial directly. Any reason for that?

acatlow

Quote from: potul on May 19, 2022, 04:35:46 AM
Nice,

just a comment: you are using the MIDI library but not using the sendControlChange() function and instead you are accessing Serial directly. Any reason for that?

In my tests when trying to use the switches to change the channels, it actually wasn't working at all and I was scratching my head wondering what exactly was happening... and also because this was my first or second sketch, I'm not exactly proficient in coding at all...

but I wanted to be able to use standalone switch functions without a midi footswitch, if I decide to incorporate it into an amp pcb design, and as the other way wasn't working, I got a little creative
Alex Catlow

Sirius Amplification
https://siriusamplification.com.au

potul

Quote from: acatlow on May 19, 2022, 07:10:56 PM
Quote from: potul on May 19, 2022, 04:35:46 AM
Nice,

just a comment: you are using the MIDI library but not using the sendControlChange() function and instead you are accessing Serial directly. Any reason for that?

In my tests when trying to use the switches to change the channels, it actually wasn't working at all and I was scratching my head wondering what exactly was happening... and also because this was my first or second sketch, I'm not exactly proficient in coding at all...

but I wanted to be able to use standalone switch functions without a midi footswitch, if I decide to incorporate it into an amp pcb design, and as the other way wasn't working, I got a little creative

Not sure if I get the point. My question was regarding using this:

  Serial.write(0xB0 | midi_channel); // CC message
  Serial.write(c); // number
  Serial.write(v); // value


When you could use this:


MIDI.sendControlChange(c,v,0xB0 | midi_channel);

Sweetalk

Quote from: potul on May 20, 2022, 05:26:07 AM

When you could use this:


MIDI.sendControlChange(c,v,0xB0 | midi_channel);


Just a little correction, you have to use midi_channel directly, like this:


MIDI.sendControlChange(c, v, midi_channel);

potul

Quote from: Sweetalk on May 20, 2022, 05:30:29 AM

Just a little correction, you have to use midi_channel directly, like this:


MIDI.sendControlChange(c, v, midi_channel);


oops, yes you are right. ... I just copy-pasted without thinking.

acatlow

just tested that and it works, Thanks!!
Alex Catlow

Sirius Amplification
https://siriusamplification.com.au

acatlow

So I've tested 100% and although a little clunky with switching, its pretty cool and I have a good base to work from...

I've made a custom PCB for it with OLEDand its working great, but I decided to change it a little to add MIDI in and MIDI out from headers to save space with the PCB

Here is the current PCB with the sketch working...

https://www.instagram.com/p/Cd3VOLbvSzB/?utm_source=ig_web_copy_link

And here is my updated code... also available to simulate here --> https://wokwi.com/projects/331591906805940818



#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
    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();
    digitalWrite(LED1,HIGH);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,LOW);
    digitalWrite(LED4,LOW);
    digitalWrite(RELAY1,HIGH);
    digitalWrite(RELAY2,LOW);
    digitalWrite(RELAY3,LOW);
    digitalWrite(RELAY4,LOW);
  }
  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
    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();
    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,HIGH);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,LOW);
    digitalWrite(RELAY1,HIGH);
    digitalWrite(RELAY2,LOW);
  }
  if (c == 87 && v >64) {
    //Channel CC MSG
    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();
    digitalWrite(LED1,LOW);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,HIGH);
    digitalWrite(RELAY1,LOW);
    digitalWrite(RELAY2,HIGH);
  }
  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
    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();
    digitalWrite(LED4,HIGH);
    digitalWrite(RELAY3,HIGH);
  }
  if (c == 88 && v <=64) {
    //Channel CC MSG
    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();
    digitalWrite(LED4,LOW);
    digitalWrite(RELAY3,LOW);
  }
  if (c == 89 && v >64) {
    //Toggle CC MSG
    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();
    digitalWrite(LED1,HIGH);
    digitalWrite(LED2,HIGH);
    digitalWrite(RELAY1,LOW);
    digitalWrite(RELAY4,HIGH);
  }
  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() {
  Serial.begin(9600);
 
  pinMode(sw1Pin, INPUT);
  pinMode(sw2Pin, INPUT);
  pinMode(sw3Pin, INPUT);
  pinMode(sw4Pin, INPUT);
  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 MIDI
  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 ");
  midiCtrlChange(88,0);
  midiCtrlChange(85,127);
  delay(200);
  display.display();
}

void loop() {
MIDI.read();

//SWITCH READOUT FUNCTIONS
sw1State = digitalRead(sw1Pin);
if (sw1State != sw1StateLast) {
  if (sw1State == HIGH){
    sw1Push++;
    if (sw1Push > 1){sw1Push = 0;}
    switch (sw1Push)
    {
      case 0:
        midiCtrlChange(89,127);
       break;
      delay(200);
      case 1:
        midiCtrlChange(88,0);
        midiCtrlChange(85,127);
      break;
      delay(200);
    }
  }
  delay(200);
  sw1StateLast = sw1State;
}

sw2State = digitalRead(sw2Pin);
if (sw2State != sw2StateLast) {
    if (sw2State == HIGH){
      sw2Push++;
      if (sw2Push > 1){sw2Push = 0;}
    switch (sw2Push)
    {
  case 0:
        midiCtrlChange(87,127);
        break;
        delay(200);
      case 1:
        midiCtrlChange(86,127);
        break;
        delay(200);
    }
  }
    sw2StateLast = sw2State;
delay(200);
}

sw3State = digitalRead(sw3Pin);
if (sw3State != sw3StateLast) {
    if (sw3State == HIGH){
      sw3Push++;
      if (sw3Push > 1){sw3Push = 0;}
      switch (sw3Push)
      {
        case 0:
          midiCtrlChange(88,0);
        break;
        delay(200);
        case 1:
          midiCtrlChange(88,127);
        break;
        delay(200);
      }
    }
    delay(200);
    sw3StateLast = sw3State;
  }

sw4State = digitalRead(sw4Pin);
if (sw4State != sw4StateLast) {
    if (sw4State == HIGH){
      sw4Push++;
      if (sw4Push > 1){sw4Push = 0;}
      switch (sw4Push)
      {
        case 1:
          midiCtrlChange(89,0);
          midiCtrlChange(85,127);
        break;
        delay(200);
        case 0:
          midiCtrlChange(89,127);
        break;
        delay(200);
      }
    }
    delay(200);
    sw4StateLast = sw4State;
  }
}

Alex Catlow

Sirius Amplification
https://siriusamplification.com.au

niektb

I have some comments on your switch handling code. But first a small stylistic suggestion:
You have the following code:

sw2Push++;
if (sw2Push > 1){sw2Push = 0;}

But as the values can only change between 1 and 0, you might as well write the following which is a bit cleaner:
sw2Push = !sw2Push;
or even (but the first suggestion is better I think):
sw2Push ^= 1;

But now the major part: I'm a bit confused about your delays in the switch case statement. Doesnt this code mean that you will always have a 200ms delay when the sw1Push is '1'?
break;
delay(200);
case 1:


Also, about this code piece:
  if (c == 85 && v >64) {
    //Channel CC MSG
    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();
    digitalWrite(LED1,HIGH);
    digitalWrite(LED2,LOW);
    digitalWrite(LED3,LOW);
    digitalWrite(LED4,LOW);
    digitalWrite(RELAY1,HIGH);
    digitalWrite(RELAY2,LOW);
    digitalWrite(RELAY3,LOW);
    digitalWrite(RELAY4,LOW);
  }

I assume you want people to be able to switch channel whilst playing a song. I'm not sure how fast the display responds (and also the code calculating the graphics) but I'd rather not find out that it delays a bit and switches channels too late. So I would advice to fírst have the digitalWrite(RELAYx, ...) statements and thén run the display code :)

acatlow

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;
  }
}

Alex Catlow

Sirius Amplification
https://siriusamplification.com.au

niektb

Quote from: acatlow on May 24, 2022, 01:58:58 AM
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

[...]

Hmm weird, it should definitely work:
QuoteThe not (!) operator returns either 0 or 1, depending on whether the input is non-zero or 0 respectively.
from https://stackoverflow.com/questions/21056180/c-not-operator-applied-to-int

QuoteI 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 wouldn't expect the delays to be thát big to instantly noticeably but maybe during a song.
I have not performed any measurements but you could :) https://www.tutorialspoint.com/calculate-time-of-operation-in-arduino

I'm just a little worried if the display will álways respond in-time. What if the i2c bus is very noisy or the power supply? (dunno where all the amps will be used but power won't be as clean as in the lab) doing the digital writes first eliminates the dependence on external hardware :)