II.3.2. Adding Foot Switch Control
Adding Main Foot Switch Button. Main user switch port (H13) is always available for the main button function. From the software point of view, the main button object is always available as button, but it need to be set up inside the init() function.button.mode is BM_TOGGLE, BM_MOMENTARY, or BM_TAPTEMPO. Without setting it up then its value will stay in its default value BM_DISABLED and the button won’t work.
The button is assumed as normally-open (N.O.) push button and connected to H13 like shown in the Figure 2.A, if the button is normally-closed (N.C) then we have to set the button.inverted to true;
If we set the button.mode as BM_TAPTEMPO then we have to set the other fields button.min, button.max, and button.value.
button.min is the minimum tap tempo value in milliseconds, the smallest acceptable value is 50, lower value will be forced to 50 by the system.
button.max is the maximum tap tempo value. After getting triggered by the first or the odd tap, if the user never complete the second or the even tap until this maximum milliseconds period elapses then the system will return the maximum value for the tap control and stop waiting for the user’s tap completion.
After calling the blackstompSetup() inside the Arduino’s setup() function, the button’s state can be accessed by its value filed (button.value, button.value, …etc.). The states or values of toggle and momentary buttons will be 0 or 1, while the value of tap tempo button would range from its minimum to its maximum field values (integer).
Each time the button’s value changes (by pressing or tapping the button), a button-change event will be generated to call an event handler. See section II.3.1.3 on how to write button’s event handler.
Adding More Button on Encoder Port. When the encoder port is not used for rotary encoder, we can use it to connect up to 3 buttons. To set it up for button, we have to set the value of encoderMode to EM_BUTTONS. After setting it then we can setup the button, button, and button in the same way as we previously setup the button
Adding More Button on Control Ports. The control ports (H1..H6) can also be used for connecting button interface, but it will treated as control object in this software point of view so it will be managed under parameter control (section II.3.1.4)
Initialization Code Example. Let’s assume if the pedal would have three buttons: a main toggle foot switch, a tap tempo button, and a a temporary button. Here is the example initialization codes:
//define your effect name
name = "GAIN DOUBLER";
//define the input mode (IM_LR or IM_LMIC)
inputMode = IM_LR;
//setting up the buttons
//setup the first button as toggle button
button.mode = BM_TOGGLE;
//enable encoder port for buttons
encoderMode = EM_BUTTONS;
//setup the second button as tap tempo button
button.mode = BM_TAPTEMPO;
button.min = 50;
button.max = 2000;
//setup the third button as temporary button
button.mode = BM_MOMENTARY;