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[0], but it need to be set up inside the init() function.button[0].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[0].inverted to true;
If we set the button[0].mode as BM_TAPTEMPO then we have to set the other fields button[0].min, button[0].max, and button[0].value.
button[0].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[0].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[0].value, button[1].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[1], button[2], and button[3] in the same way as we previously setup the button[0]
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
void gainDoubler::init() { //select the appropriate device by uncommenting one of the following two lines: //setDeviceType(DT_ESP32_A1S_AC101); setDeviceType(DT_ESP32_A1S_ES8388); //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[0].mode = BM_TOGGLE; //enable encoder port for buttons encoderMode = EM_BUTTONS; //setup the second button as tap tempo button button[1].mode = BM_TAPTEMPO; button[1].min = 50; button[1].max = 2000; //setup the third button as temporary button button[2].mode = BM_MOMENTARY; } |