I am currently building a synthesizer using the MOZZI library, for controls it has 3 potentiometers and a push button switch. I would like to program it so that when the button is held the potentiometers will change one set of 3 variables and when the button is released they will control a different set of 3 variables. Effectively each potentiometer will control 2 different variables, depending on what state the switch is in. The issue I am having using conditional statements is that when the potentiometer is controlling one variable, the other variable is flickering randomly and vice versa. When not being controlled by the potentiometer I would like each variable to hold its last value. Have I made a mistake in my code or should I be approaching this in a different way? I have included the control portion of my sketch below where I am trying to have INPUT_PIN1 control the variable 'pitch' when the switch is up and 'cutoff' when the switch is depressed.
void updateControl(){
//assign variables to analog pin
int detune = mozziAnalogRead(INPUT_PIN0);
int vol = mozziAnalogRead(INPUT_PIN2);
int pitch;
int cutoff;
if(digitalRead(8) == LOW) { // here is where the switch selects which value is controlled by the potentiometer
pitch = mozziAnalogRead(INPUT_PIN1);
}
else {
cutoff = mozziAnalogRead(INPUT_PIN1);
}
pitch = map(pitch, 0, 1023, 65, 262); // map the pot range (0-1023 to a new set of values)
cutoff = map(cutoff, 0, 1023, 10, 255);
vol = map(vol, 0, 1023, 10, 255);
detune = map(detune, 0, 1023, 0, 100);
detune = (detune*0.05);
lpf.setCutoffFreq(cutoff);
aSaw.setFreq(pitch); //assign variables to oscilator parameters
bSaw.setFreq(pitch * detune);
aSin.setFreq((pitch)/2);
}