# Arduino Micro and button box help

**URL:** <https://forum.arduino.cc/t/arduino-micro-and-button-box-help/1266375>\
**Category:** Interfacing w/ Software on the Computer\
**Created:** [May 31, 2024, 9:41am UTC](https://forum.arduino.cc/t/arduino-micro-and-button-box-help/1266375 "2024-05-31T09:41:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffmorris1956](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jeffmorris1956/32/1126981_2.png) [@jeffmorris1956](https://forum.arduino.cc/u/jeffmorris1956)\
**Post date:** [May 31, 2024, 9:41am UTC](https://forum.arduino.cc/t/arduino-micro-and-button-box-help/1266375/1 "2024-05-31T09:41:39Z")

</div>

I have Arduino Micro and I want to create a button box that has 10 buttons connected to D2 thru D12 for driving games. I tried different joystick/gamepad libraries but they don't work. How do I create code in Arduino IDE ?

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [May 31, 2024, 9:52am UTC](https://forum.arduino.cc/t/arduino-micro-and-button-box-help/1266375/2 "2024-05-31T09:52:34Z")

</div>

are you sure it's an Arduino Micro?

what code / library did you try? what did not work?

---

<div class="post-metadata">

**Author:** ![PaulRB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulrb/32/216330_2.png) [@PaulRB](https://forum.arduino.cc/u/PaulRB)\
**Post date:** [May 31, 2024, 10:06am UTC](https://forum.arduino.cc/t/arduino-micro-and-button-box-help/1266375/3 "2024-05-31T10:06:36Z")

</div>

> [@jeffmorris1956](#):
>
> I tried different joystick/gamepad libraries but they don't work

Probably they do work but you did not use them correctly.

Please never say "doesn't/don't work". It is very unhelpful to those trying to help you. Always describe what happened when you tried and how that was different from what you expected/wanted.

> [@jeffmorris1956](#):
>
> How do I create code in Arduino IDE ?

You type it into the main window of the IDE.

Also you can copy and paste it in, but then you are not really creating it 🙂

If you don't know how to use the IDE, how did you test any libraries at all?

---

<div class="post-metadata">

**Author:** ![jeffmorris1956](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jeffmorris1956/32/1126981_2.png) [@jeffmorris1956](https://forum.arduino.cc/u/jeffmorris1956)\
**Post date:** [May 31, 2024, 11:51am UTC](https://forum.arduino.cc/t/arduino-micro-and-button-box-help/1266375/4 "2024-05-31T11:51:00Z")

</div>

I want the Arduino Micro to show up as game controller in "Printers and Devices" window so that I can assign buttons to commands such as ignition switch to button 1 and engine start to button 2 in driving games. If I right-click on Arduino Micro in "Printers and Devices" window, choose "Game Controller Settings", and choose "Properties", I get the test window where I can press buttons to see which button LED light up. I tried one of joystick libraries and when I press a button, the button LEDs light up in a row.

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [May 31, 2024, 11:57am UTC](https://forum.arduino.cc/t/arduino-micro-and-button-box-help/1266375/5 "2024-05-31T11:57:52Z")

</div>

Please show your code (using code tags - please) and how you wired the buttons.

---

<div class="post-metadata">

**Author:** ![jeffmorris1956](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jeffmorris1956/32/1126981_2.png) [@jeffmorris1956](https://forum.arduino.cc/u/jeffmorris1956)\
**Post date:** [May 31, 2024, 3:22pm UTC](https://forum.arduino.cc/t/arduino-micro-and-button-box-help/1266375/6 "2024-05-31T15:22:53Z")

</div>

I tried this code and it worked.

```arduino
// Simple example application that shows how to read four Arduino
// digital pins and map them to the USB Joystick library.
//
// Ground digital pins 9, 10, 11, and 12 to press the joystick 
// buttons 0, 1, 2, and 3.
//
// NOTE: This sketch file is for use with Arduino Leonardo and
// Arduino Micro only.
//
// by Matthew Heironimus
// 2015-11-20
//--------------------------------------------------------------------

#include <Joystick.h>

Joystick_ Joystick;

void setup() {
  // Initialize Button Pins
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);

  // Initialize Joystick Library
  Joystick.begin();
}

// Constant that maps the phyical pin to the joystick button.
const int pinToButtonMap = 2;

// Last state of the button
int lastButtonState[6] = {0,0,0,0,0,0};

void loop() {

  // Read pin values
  for (int index = 0; index < 6; index++)
  {
    int currentButtonState = !digitalRead(index + pinToButtonMap);
    if (currentButtonState != lastButtonState[index])
    {
      Joystick.setButton(index, currentButtonState);
      lastButtonState[index] = currentButtonState;
    }
  }

  delay(50);
}

```

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [May 31, 2024, 3:36pm UTC](https://forum.arduino.cc/t/arduino-micro-and-button-box-help/1266375/7 "2024-05-31T15:36:22Z")

</div>

surprise 🙂

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 27, 2024, 3:36pm UTC](https://forum.arduino.cc/t/arduino-micro-and-button-box-help/1266375/8 "2024-11-27T15:36:27Z")

</div>

Closed on November 27, 2024, 3:36pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
