Jump to content
  • Sign Up

Programmable Footswitches DIY Tutorial


Recommended Posts

First things first: I have no idea if this tutorial is in the right place. If not, I would like to ask a moderator to move it into a fitting section of this forum.

Once upon a time I got me some programmble footswitches called StealthSwitch3. They did the job. I bound four pedals to W, S, Q and E (for movement) and the last to "Scroll lock" for push-to-talk. Recently one of the pedal failed. Luckily I could repair the pedal, but doing research for a replacement I found out, that product got discontinued. But I wanted a second set for my other computer too. A pedal for push-to-talk is very nice.

You can get footpedal switches for next to nothing on ebay. I opted for more solid ones, but you can get them in all shapes and sizes. I paid 10€ for a pedal.

Because my stealthswich3 uses 1/8" jacks and plugs I chosen those for the new set too. That way I can switch pedals between both sets.

But to be honest: That was a stupid idea. The jacks are quite finicky to work with and a closed contact had cost me hours of debugging. I would advise to use 1/4". Those are used for music related stuff and you can buy pedals with a cable and a 1/4" plug alreadys attached to it. But the needed cables for my use were quite cheap. I paid 1,25€ for a cable and 35 cents for a jack.

To control everything I opted for an arduino micro compatible micro computer with a ATMega32U4. It is a tiny thing that can emulate a HID controller (mouse, keyboard, etc) on PC. I got mine for 13,90€.
As a case for the arduino and jacks I bought a small, sturdy one out of aluminium. It will live under the desk and should be sturdy enough.

The last part I needed was a cable with a micro USB cable with a standard USB A plug on the other end. I guess most have some already around, but I wanted a new one and paid 3,39€.

For soldering, I had some old cables around. The soldering is extermely simple:

  1. Close the tiny bridge near the jack, so the arduino will run over the USB power.
  2. Connect the ground to the sleve solder pin of your first jack. Then connect from there all other jacks.
  3. Connect the pin 2 to the tip pin of your first jack. Pin 3 goes to the tip pin of your second jack and so on. I used five pedals in my case. So pin 2 up to pin 6 are in use.

Prepare the case of your choice. For the 1/8" jacks I could use a 6mm drill. I used the same drill and a dremel to add a slit for the USB cable.

I used velcro to install the arduino. The tiny pcb weights next to nothing and so I can easily take it out again.

To program your Arduino you need the software. It can be found here: https://www.arduino.cc/en/software

Now you select your type of Arduino: Tools > Board > Arduino AVR Boards > Arduino Micro

Furthermore you have to install a library. But fear not, this can be done inside of the Arduino IDE. Under “Tools > Manage Libraries” search for “LC_baseTools” and install it.

The sketch has a debug define, that can be set to “true”. That way you can see any status changes on the serial console. It can be useful to debug your wiring, should you have grounded something or have a cold soldering joint.

The values for the buttons are just at the top section of the script. You can change them to your liking.

Of course you could strip the sketch down, should you need less switches or enlarge it, should you want more.

Finally you insert this code into your sketch. The sketch is the program you compile and upload.

Spoiler
// A lot of mechanical buttons have the problem that they bounce. You can
// work around that with delay settings, to ignore the later bouncing 
// switch impulses. But it is problematic as switches age and a value that 
// worked fine might not do after some months or years. On the other hand, 
// you want to keep the value as low as possible.
//
// Thankfully there is a better way:
//
// The mechButton class, which is part of the LC_baseTools library.
// "This does NOT use hardcoded delay() for debouncing. It actually uses
//  a digital filter to sense when the button stops bouncing. And is 
//  totally non-blocking to boot." by jimLee
//
// Example:
// https://wokwi.com/projects/391133606159541249
// This Sketch uses a lot from the example. Thanks a lot to jimLee
// for his great library and example!
//
// You have to install the LC_baseTools library into your Arduino IDE to
// use the mechButton class.
//
// Including the mechButton library with a Class that creates a 
// debounced button.
#include <mechButton.h>

// Including the keyboard library for keyboard key defines
#include <Keyboard.h>

// Including the mouse library for mouse action defines
#include <Mouse.h>  

// Setting defines for the used pins to make it better readable
#define PIN_A	2
#define PIN_B	3
#define PIN_C	4
#define PIN_D	5
#define PIN_E	6

// Set define to true to enable debug
#define DEBUG_VALUE false

// The Values for my Keys
const char keyValueA = 'w';
const char keyValueB = 's';
const char keyValueC = 'q';
const char keyValueD = 'e';
const char keyValueE = KEY_SCROLL_LOCK;

// create the mechButtons objects for the callbacks later
mechButton aButton(PIN_A);
mechButton bButton(PIN_B);
mechButton cButton(PIN_C);
mechButton dButton(PIN_D);
mechButton eButton(PIN_E);


// Your standard sketch setup()
void setup()
{
  // start the serial should debug is enabled
  if(DEBUG_VALUE == true)
  {
    Serial.begin(9600); 
  }

  // Set up our callback. (Also calls hookup() for idling.)
  aButton.setCallback(aCallback);
  bButton.setCallback(bCallback);
  cButton.setCallback(cCallback);
  dButton.setCallback(dCallback);
  eButton.setCallback(eCallback);
}


// This is the function that's called when the A button changes state.
void aCallback(void)
{
  if(DEBUG_VALUE == true)
  {
    Serial.print("A Button just became ");
  }

  if (aButton.getState())
  {
    if(DEBUG_VALUE == true)
    {
      Serial.println("true!");
    }
    // released the pressed key
    Keyboard.release(keyValueA);
  }
  else
  {
    if(DEBUG_VALUE == true)
    {
      Serial.println("false!");
    }
    // press the key
    Keyboard.press(keyValueA);
  }
}


// This is the function that's called when the B button changes state.
void bCallback(void)
{
  if(DEBUG_VALUE == true)
  {
    Serial.print("B Button just became ");
  }

  if (bButton.getState())
  {
    if(DEBUG_VALUE == true)
    {
      Serial.println("true!");
    }
    // released the pressed key
    Keyboard.release(keyValueB);
  }
  else
  {
    if(DEBUG_VALUE == true)
    {
      Serial.println("false!");
    }
    // press the key
    Keyboard.press(keyValueB);
  }
}


// This is the function that's called when the C button changes state.
void cCallback(void)
{
  if(DEBUG_VALUE == true)
  {
    Serial.print("C Button just became ");
  }

  if (cButton.getState())
  {
    if(DEBUG_VALUE == true)
    {
      Serial.println("true!");
    }
    // released the pressed key
    Keyboard.release(keyValueC);
  }
  else
  {
    if(DEBUG_VALUE == true)
    {
      Serial.println("false!");
    }
    // press the key
    Keyboard.press(keyValueC);
  }
}


// This is the function that's called when the D button changes state.
void dCallback(void)
{
  if(DEBUG_VALUE == true)
  {
    Serial.print("D Button just became ");
  }

  if (dButton.getState())
  {
    if(DEBUG_VALUE == true)
    {
      Serial.println("true!");
    }
    // released the pressed key
    Keyboard.release(keyValueD);
  }
  else
  {
    if(DEBUG_VALUE == true)
    {
      Serial.println("false!");
    }
    // press the key
    Keyboard.press(keyValueD);
  }
}


// This is the function that's called when the E button changes state.
void eCallback(void)
{
  if(DEBUG_VALUE == true)
  {
    Serial.print("E Button just became ");
  }

  if (eButton.getState())
  {
    if(DEBUG_VALUE == true)
    {
      Serial.println("true!");
    }
    // released the pressed key
    Keyboard.release(keyValueE);
  }
  else
  {
    if(DEBUG_VALUE == true)
    {
      Serial.println("false!");
    }
    // press the key
    Keyboard.press(keyValueE);
  }
}


// the permanent running loop
void loop()
{
  // Let all the idlers have time to do their thing.  
  idle();
}

 

Edited by Wetterburg.4052
typo
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...