Newbie question! need help with simple code for a guitarpedal switchingsystem
Hi!
I am new to the arduino forum and asking for some help with a new project I have started a month ago. I am still new with the arduino coding, so bare with me
The gadget that I want to build is a guitarpedal switchingsystem. Easily explained the arduino takes in information from trigger buttons and opens diffrent outputports, sending electrical current to relays. When a relay is on it lets the guitarsignal go through a guitarpedal, this is the basic idea!. For future development I want to be able to receive and send midi, change amp channels.
My theory has been that I would be able to solve it with an âif-statementâ and a âswitch case-statementâ. The âif-statementâ would work so that depending on which button is pushed it would change an integer value. The âswitch case-statementsâ would then have a case of open/closed ports for each value that the integer would give it. But for some reason I donât get it to work and I believe it is and programming error. Any feedback is welcome!
Here is my code:
(The ports that control the relays are namned after lights)
//portnumbers for the lights
const int lightRed = 13;
const int lightBlue = 12;
const int lightYellow = 11;
//portnumber to buttons
const int switchButton1 = 2;
const int switchButton2 = 3;
int patchnumber = 0;
void setup() {
pinMode(lightRed, OUTPUT);
pinMode(lightBlue, OUTPUT);
pinMode(lightYellow, OUTPUT);
pinMode(switchButton1, INPUT);
pinMode(switchButton2, INPUT);
digitalWrite(lightRed, LOW);
digitalWrite(lightBlue, LOW);
digitalWrite(lightYellow, LOW);
}
//if-statement
void loop() {
int state1 = digitalRead(switchButton1);
if(state1 == HIGH){
patchnumber = 1;
}
int state2 = digitalRead(switchButton2);
if(state2 == HIGH){
patchnumber = 2;
}
//switch-case satement
switch (patchnumber) {
case 0:
digitalWrite(lightRed, HIGH);
digitalWrite(lightBlue, LOW);
digitalWrite(lightYellow, LOW);
break;
case 1:
digitalWrite(lightRed, HIGH);
digitalWrite(lightBlue, LOW);
digitalWrite(lightYellow, LOW);
break;
case 2:
digitalWrite(lightRed, LOW);
digitalWrite(lightBlue, LOW);
digitalWrite(lightYellow, HIGH);
break;
}
}