Had some difficulty with getting it to work with the methods described in the various answers. So i tried it using various if statements and got it to work.
It is probably not the best way of programming and I will make it more efficient, because there is a lot of repetition in the code, but it works!!
I still have to include sending the midi signals per function, but that was working in my original sketch so I can copy that in, without any issues.
Thanks for all the help! Although I wasn't able to get it all incorporated, it did make me push through.
Code for anyone who is interested:
//buttons, leds en kanalen vastleggen
const int switch1 = 8;
const int switch2 = 9;
const int switch3 = 10;
const int switch4 = 11;
const int switch5 = 12;
const int led1 = A0;
const int led2 = A1;
const int led3 = A2;
const int led4 = A3;
const int led5 = A4;
const int peaveyChannel = 2;
const int peaveyBoost = 3;
const int peaveyReverb = 4;
const int peaveyLoop = 5;
//switches en status definieren
int switch1State = 0;
int switch2State = 0;
int switch3State = 0;
int switch4State = 0;
int switch5State = 0;
int prevSwitch1State = 0;
int prevSwitch2State = 0;
int prevSwitch3State = 0;
int prevSwitch4State = 0;
int prevSwitch5State = 0;
void setup() {
// type kanaal in- of uit vastleggen
Serial.begin(9600); //not needed now, but left in to monitor the variables during debugging.
pinMode(switch1, INPUT_PULLUP);
pinMode(switch2, INPUT_PULLUP);
pinMode(switch3, INPUT_PULLUP);
pinMode(switch4, INPUT_PULLUP);
pinMode(switch5, INPUT_PULLUP);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(peaveyChannel, OUTPUT);
pinMode(peaveyBoost, OUTPUT);
pinMode(peaveyReverb, OUTPUT);
pinMode(peaveyLoop, OUTPUT);
}
void loop()
//per switch een wijziging detecteren en daarna de functie voor kanaalwijziging aanroepen
{
switch1State = digitalRead(switch1);
// if (switch1State =!prevSwitch1State){
if (switch1State == LOW) {
channel1();
// prevSwitch1State = switch1State;
// }
}
switch2State = digitalRead(switch2);
// if (switch2State =!prevSwitch2State){
if (switch2State == LOW) {
channel2();
// prevSwitch2State = switch2State;
// }
}
switch3State = digitalRead(switch3);
// if (switch3State =!prevSwitch3State){
if (switch3State == LOW) {
channel3();
// prevSwitch3State = switch3State;
// }
}
switch4State = digitalRead(switch4);
// if (switch4State =!prevSwitch4State){
if (switch4State == LOW) {
channel4();
// prevSwitch4State = switch4State;
// }
}
switch5State = digitalRead(switch5);
// if (switch5State =!prevSwitch5State){
if (switch5State == LOW) {
channel5();
// prevSwitch5State = switch5State;
// }
}
}
//functie alle leds uit bij inschakelen nieuw kanaal en kanalen naar default
void AllOff(){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(peaveyChannel, LOW);
digitalWrite(peaveyBoost, LOW);
digitalWrite(peaveyReverb, LOW);
digitalWrite(peaveyLoop, LOW);
}
//functies per kanaalkeuze
void channel1(){
AllOff();
digitalWrite(led1, HIGH);
digitalWrite(peaveyChannel, LOW);
digitalWrite(peaveyBoost, LOW);
digitalWrite(peaveyReverb, LOW);
digitalWrite(peaveyLoop, LOW);
}
void channel2(){
AllOff();
digitalWrite(led2, HIGH);
digitalWrite(peaveyChannel, HIGH);
digitalWrite(peaveyBoost, LOW);
digitalWrite(peaveyReverb, LOW);
digitalWrite(peaveyLoop, LOW);
}
void channel3(){
AllOff();
digitalWrite(led3, HIGH);
digitalWrite(peaveyChannel, HIGH);
digitalWrite(peaveyBoost, HIGH);
digitalWrite(peaveyReverb, LOW);
digitalWrite(peaveyLoop, LOW);
}
void channel4(){
AllOff();
digitalWrite(led4, HIGH);
digitalWrite(peaveyChannel, LOW);
digitalWrite(peaveyBoost, HIGH);
digitalWrite(peaveyReverb, LOW);
digitalWrite(peaveyLoop, LOW);
}
void channel5(){
AllOff();
digitalWrite(led5, HIGH);
digitalWrite(peaveyChannel, LOW);
digitalWrite(peaveyBoost, LOW);
digitalWrite(peaveyReverb, LOW);
digitalWrite(peaveyLoop, HIGH);
}