pro mini continuous key press

Hy.

I’m fairly new to any arduino programming or programming in general to be honest.

I’m making a game controller for the raspberry pi.

I programmed it to act like a keyboard (I need it to act like a keyboard not like a controller) but I noticed thare is one problem using it like this. If I press any button and keep it pressed it doesn’t register it like a continously pressed button. It treats it like a button being pressed multiple times in succession.

I am not a programmer I learn as I go.

The code I used is a modified code from the sparkfun keayboard example page (I haven’t tweaked the delay yet):

#include <Keyboard.h>

int up = 1;  // Set a button to any pin
int down = 0;
int left = 2;
int right = 3;
int select = 4;
int start = 5;
int buttonY = 6;
int buttonX = 7;
int buttonB = 8;
int buttonA = 9;
int L1 = 10;
int R1 = 16;

void setup()
{
  pinMode(up, INPUT);  // Set the button as an input
  digitalWrite(up, HIGH);  // Pull the button high
  
  pinMode(down, INPUT);  // Set the button as an input
  digitalWrite(down, HIGH);  // Pull the button high

    pinMode(left, INPUT);  // Set the button as an input
  digitalWrite(left, HIGH);  // Pull the button high

    pinMode(right, INPUT);  // Set the button as an input
  digitalWrite(right, HIGH);  // Pull the button high

    pinMode(select, INPUT);  // Set the button as an input
  digitalWrite(select, HIGH);  // Pull the button high

    pinMode(start, INPUT);  // Set the button as an input
  digitalWrite(start, HIGH);  // Pull the button high

    pinMode(buttonY, INPUT);  // Set the button as an input
  digitalWrite(buttonY, HIGH);  // Pull the button high

      pinMode(buttonX, INPUT);  // Set the button as an input
  digitalWrite(buttonX, HIGH);  // Pull the button high

      pinMode(buttonB, INPUT);  // Set the button as an input
  digitalWrite(buttonB, HIGH);  // Pull the button high

      pinMode(buttonA, INPUT);  // Set the button as an input
  digitalWrite(buttonA, HIGH);  // Pull the button high

      pinMode(L1, INPUT);  // Set the button as an input
  digitalWrite(L1, HIGH);  // Pull the button high

      pinMode(R1, INPUT);  // Set the button as an input
  digitalWrite(R1, HIGH);  // Pull the button high
}

void loop()
{
  if (digitalRead(up) == 0)  // if the button goes low
  {
    Keyboard.write('w');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }
    if (digitalRead(down) == 0)  // if the button goes low
  {
    Keyboard.write('s');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

      if (digitalRead(left) == 0)  // if the button goes low
  {
    Keyboard.write('a');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

      if (digitalRead(right) == 0)  // if the button goes low
  {
    Keyboard.write('d');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

      if (digitalRead(select) == 0)  // if the button goes low
  {
    Keyboard.write('.');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

      if (digitalRead(start) == 0)  // if the button goes low
  {
    Keyboard.write('\n');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

        if (digitalRead(buttonY) == 0)  // if the button goes low
  {
    Keyboard.write('y');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

        if (digitalRead(buttonX) == 0)  // if the button goes low
  {
    Keyboard.write('x');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

        if (digitalRead(buttonB) == 0)  // if the button goes low
  {
    Keyboard.write('c');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

        if (digitalRead(buttonA) == 0)  // if the button goes low
  {
    Keyboard.write('v');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

        if (digitalRead(L1) == 0)  // if the button goes low
  {
    Keyboard.write('q');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

        if (digitalRead(R1) == 0)  // if the button goes low
  {
    Keyboard.write('e');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }
}

consider the following (you will need to define buttonAPressed (and any other buttonPressed bools you may need)

if (digitalRead(buttonA) == 0)  // if the button goes low
  {
    if buttonAPressed == false  // if button was not previously pressed
      {
      buttonAPressed := True;  // flag that the button was pressed (so there aren't a kajillion characters)

      Keyboard.write('v');  // send a 'z' to the computer via Keyboard HID
      // remove the delay - (NOT NEEDED)  // delay(100);  // delay so there aren't a kajillion z's
      }
  }
else
  {
      buttonAPressed := false;
  }

no matter how long you hold the button, you will only get one