Usb Foot Pedal

Hello,

I'm new to the arduino world, and I am currently running into a issue. The issue is when the switch is pressed, I get a very sporadic response, if at all. My long term goal will be to have a simple foot pedal, which will sent "CTRL", to use with discord and activate the mic. Any help I can get would be great.

Setup:

1 Leonardo Pro Micro
1 Micro Switch (Com to GRD, and NO to Pin 2 on Pro Micro)

#include <Keyboard.h>


const int buttonPin = 2;
void setup() {
  pinMode(buttonPin, INPUT);
  Keyboard.begin();
  delay(1000);
}


int buttonState = 0;
int key = 'n';

void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    Keyboard.press(key);
  } else if (buttonState == LOW) {
    Keyboard.releaseAll();
  }
  delay(100);
}

Try INPUT_PULLUP instead of INPUT on you pin mode.

a7

I got it working, ended up doing some more googling and found something I could tinker with.

#include <Keyboard.h>

void setup() {
  pinMode(2,INPUT_PULLUP); 
  pinMode(3,INPUT_PULLUP);

 Serial.begin(115200);    //begin seral comms for debugging
}

char ctrlKey = KEY_LEFT_CTRL;

void loop() {
  Keyboard.begin();
  if (digitalRead(3) == 0) //if button 3 is pushed
   {
Keyboard.press(ctrlKey);
delay(200);
Keyboard.releaseAll();
}
  Keyboard.end();
}