Normally you should read switches with the Bounce library. You can also use digitalRead(), but Bounce is better because it will automatically deal with mechanical chatter in the switch.
Most of the audio library tutorial examples use Bounce to read 3 pushbuttons, so I'd suggest checking out the tutorial.
https://www.pjrc.com/store/audio_tutorial_kit.html
You should connect 1 wire from the switch to an unused digital pin and the other wire to GND. Near the beginning of your program, create a Bounce object (as in the tutorial examples), like this if using pin 2.
Code:
Bounce button2 = Bounce(2, 15);
Then in setup(), configure the pin for INPUT_PULLUP mode, like this:
Code:
pinMode(2, INPUT_PULLUP);
Near the end of setup you will also need some code to read the switch and set up the initial state of the input select. It should look like this:
Code:
delay(10);
button2.update();
if (button2.read()) {
sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
} else {
sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
}
The delay may or may not be necessary, but I recommend using a short delay in case there is very little time between configuring the pin and this code. Those input pullups are weak and can take a short time to actually change the pin's voltage.
Then inside loop, you'll need code like this.
Code:
button2.update();
if (button2.risingEdge()) {
sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
}
if (button2.fallingEdge()) {
sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
}
Every time loop() runs, this will check if the switch has changed. If it does, the input mode is changed. Simple, right?