Using Trinket as a 3 switch keypad, but the last key switch continuously repeats

Hi guys,

I'm new to all this, but I've soldered 3 cherry switches to my Trinket via pin # 0,1,2

I'm following Adafruit's tutorial example for the code, with the additional of a keyswitch on pin #1.

The code is below. Pin 2 (Enter), and pin 0 (Backspace) works fine. Pin 1 (A) works as well, except that it keeps typing "A"s until I pull the plug on the Trinket.

Can anyone please point me in the right direction on what to change, so that the pin #1 switch (A), doesn't continuously repeat itself?

Thank you in advance!

#include <TrinketKeyboard.h>

#define PIN_BUTTON_ENTER     2
#define PIN_BUTTON_BACKSPACE  0
#define PIN_BUTTON_A  1

void setup()
{
  // button pins as inputs
  pinMode(PIN_BUTTON_ENTER, INPUT);
  pinMode(PIN_BUTTON_BACKSPACE, INPUT);
  pinMode(PIN_BUTTON_A, INPUT);

  // setting input pins to high means turning on internal pull-up resistors
  digitalWrite(PIN_BUTTON_ENTER, HIGH);
  digitalWrite(PIN_BUTTON_BACKSPACE, HIGH); 
  digitalWrite(PIN_BUTTON_A, HIGH);
  // remember, the buttons are active-low, they read LOW when they are not pressed

  // start USB stuff
  TrinketKeyboard.begin();
}

void loop()
{
  TrinketKeyboard.poll();
  // the poll function must be called at least once every 10 ms
  // or cause a keystroke
  // if it is not, then the computer may think that the device
  // has stopped working, and give errors

  if (digitalRead(PIN_BUTTON_ENTER) == LOW)
  {
    TrinketKeyboard.pressKey(0, KEYCODE_ENTER);
    // this should press end
    TrinketKeyboard.pressKey(0, 0);
    // this releases the key
    delay(500);
  }

  if (digitalRead(PIN_BUTTON_BACKSPACE) == LOW)
  {
    TrinketKeyboard.pressKey(0, KEYCODE_BACKSPACE);
    // this should press home using the led 
    TrinketKeyboard.pressKey(0, 0);
    // this releases the key
    delay(500);
  }
  
  if (digitalRead(PIN_BUTTON_A) == LOW)
  {
    TrinketKeyboard.pressKey(0, KEYCODE_A);
    // this should press insert
    TrinketKeyboard.pressKey(0, 0);
    // this releases the key
    delay(500);
  }
}

Can anyone please point me in the right direction on what to change

Change the pin that the switch is soldered to. Choose a pin that does NOT have other uses that you need.

PaulS:
Change the pin that the switch is soldered to. Choose a pin that does NOT have other uses that you need.

Hi Paul,

Thank you so much for your reply. The repeating keyswitch is soldered to pin #1, it is not used by anything else I don't think (it's connected to the LED i think though, according this this: Pinouts | Introducing Trinket | Adafruit Learning System ).

There is still #3 and #4, but based on the Trinket documentation, those are not to be used since they are for the USB interface, correct? Anyway, I tried soldering the repeating keyswitch to #3, but the problem of repeating key input persists.

I appreciate your help, if you have any other suggestion, please let me know!

Do you have external resistors along with your switches? Or do you have floating pins?

Does the Trinket/AtTiny85 have internal pullups that you can turn on?

A schematic is definitely in order.

In "Adafruit Trinket mini", pin 1 is used for LED.
Therefore, when the LED is lit it will be nearly LOW level.

The easiest measure is to remove the LED.
Since this method can not use the LED, it is a trade-off.