I need help with a pro micro keyboard project

So first off I’m really new to Arduino so sorry if I don’t make sense. I have the code working with my pro micro board normally for a basic usb keyboard but I was wondering how I could make it only type one character when the key gets released. I also don’t want it to keep typing the character without a delay because I want to be able to click it quickly but not automatically typing. Basically one character per key release. Sorry if that doesn’t make sense. Thanks in advance!

Please, show your the code... be sure to post it in a <CODE> block.

AND a wiring diagram to verify the code is correct.

Yes I will upload that in a little. Sorry about that.

#include <Keyboard.h>                               

int pinA = 2;                                       
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 7;

void setup() {

pinMode(pinA, INPUT_PULLUP);                        
pinMode(pinB, INPUT_PULLUP);                        
pinMode(pinC, INPUT_PULLUP);
pinMode(pinD, INPUT_PULLUP);
pinMode(pinE, INPUT_PULLUP);
pinMode(pinF, INPUT_PULLUP);

}

void loop() {

  if (digitalRead(pinA) == LOW)                     
  {
    Keyboard.write('1');                           
    delay(1500);
  }
  if (digitalRead(pinB) == LOW)                     
  {
    Keyboard.write('2');         
    delay(500);
  }

  if (digitalRead(pinC) == LOW)                     
    Keyboard.write('3'); 
    delay(500);
  }

  if (digitalRead(pinD) == LOW)                     
  {
    Keyboard.write('4')
  }

  if (digitalRead(pinE) == LOW)                    
  {
    Keyboard.write('5');
    delay(500);                                     
  }
  if (digitalRead(pinF) == LOW)                     
  {
    Keyboard.write('6');
    delay(500);                                     
  }
}

Are you having this problem with all keys, or just the "4" key?

right now I only have A and B hooked up into my project. but I do see there is no delay. What I ideally would want is when the key is released to then output a single number no matter how long I hold the button for. I also would want that delay to reset so I could immediately click It again with having to wait

You will need to compare the new state to the old state. If the old state and the new state are equal, key is either not pressed or is held (so ignore this key). If the old state is "pressed" and new state is "not pressed" then the key is released (so time to read another key). If the old state is "not pressed" and new state is "pressed" a new key was pressed.

To elaborate and extend @xfpd's advice, and give the entire matter names for the very common problems you are addrsssing.

There are two problems with push buttons. One is solved by "state change detection", there's an examlpe in the IDE and it goes with this article

https://docs.arduino.cc/built-in-examples/digital/StateChangeDetection/

It means you operate on the changes. Here's the idea in pseudocode:

  read the button (once, into a variable, use that for the next lines)
  if the reading has changed {
    if the reading is now pressed {
      do the thing you wanna do when you press the button
    }
    record the current state
  }

By record I mean save that reading in a variable for comparison fo the next button reading.

The other problem is that buttons when pressed or released bounce. "debouncing" is the term of art here, and there are many ways to solve it. Buttons bounce faster than you can see, but so slow that code can be so fast as to think you d pressed the button 417 times.

The very easiest way, and satisfactory and legit in many circumstances is to simply slow the loop() down so that button bouncing is way faster.

As the last line in your loop, just waste a bit of time, viz:

  delay(20);  // poor man's debouncing
}

It's called poor man's debouncing here because it is crude and dumb and very inexpensive and easy to implement.

Later you can look into superior debouncing techniques.

Both these issues come up alla time, and knowing them and how to solve the problems they cause is worth all the time you can give it, as early as you can manage to find the time.

Even if you never did need either, both are interesting problems with intersting solutions and seeing how code works at that level and maybe even writing your own code will be educational. No a waste of time.

HTH

a7