Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1x Arduino Pro Micro (atmega32u4) clone
- https://www.aliexpress.com/item/32648920631.html
- 1x 8-way Suzo Happ competition joystick (color variety available)
- https://na.suzohapp.com/products/joysticks/50-6070-120
- 10x Suzo Happ pushbuttons with .187 switches (color variety available)
- https://na.suzohapp.com/products/pushbuttons/58-9100-L
- 1x Suzo Happ 1p start button with .187 switch
- https://na.suzohapp.com/products/pushbuttons/58-9111-L1PLY
- ~30x .187 female spade connectors
- https://www.amazon.com/dp/B01GYFMCE6
- 2x Custom modded OpenCADE 3d printed box
- https://www.thingiverse.com/thing:3445410
- 2x Custom modded OpenCADE 3d printed panel
- https://www.thingiverse.com/thing:3491239
- 1 standard unmodified box and panel can fit 6+2 buttons and a joystick.
- Write some simple code using Arduino joystick library
- https://github.com/MHeironimus/ArduinoJoystickLibrary
- Sample work-in-progress (but functional) code...
- #include <Joystick.h>
- #define BUTTON_COUNT 11
- #define JOY_BUTTON_COUNT 4
- #define HAT_COUNT 0
- enum button_names {
- BUTTON_SELECT,
- BUTTON_START,
- BUTTON_A,
- BUTTON_B,
- BUTTON_X,
- BUTTON_Y,
- BUTTON_L1,
- BUTTON_R1,
- BUTTON_L2,
- BUTTON_R2,
- BUTTON_COIN,
- };
- enum joy_button_names {
- JOY_UP,
- JOY_RIGHT,
- JOY_DOWN,
- JOY_LEFT,
- };
- int button_pins[BUTTON_COUNT] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
- int joy_button_pins[JOY_BUTTON_COUNT] = {18, 19, 20, 21};
- // Last state of the buttons
- int last_button_state[BUTTON_COUNT] = { };
- // Last state of the joystick
- int last_joy_button_state[JOY_BUTTON_COUNT] = { };
- Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD,
- BUTTON_COUNT, HAT_COUNT, // Button Count, Hat Switch Count
- true, true, false, // X and Y, but no Z Axis
- false, false, false, // No Rx, Ry, or Rz
- false, false, // No rudder or throttle
- false, false, false); // No accelerator, brake, or steering
- void setup() {
- // Initialize Button Pins
- for (int pin_num = 0; pin_num < BUTTON_COUNT; pin_num++) {
- pinMode(button_pins[pin_num], INPUT_PULLUP);
- }
- for (int pin_num = 0; pin_num < JOY_BUTTON_COUNT; pin_num++) {
- pinMode(joy_button_pins[pin_num], INPUT_PULLUP);
- }
- // Initialize Joystick Library
- Joystick.begin();
- Joystick.setXAxisRange(-1, 1);
- Joystick.setYAxisRange(-1, 1);
- }
- void loop() {
- // Read pin values
- for (int index = 0; index < BUTTON_COUNT; index++)
- {
- int current_state = !digitalRead(button_pins[index]);
- if (current_state != last_button_state[index])
- {
- switch (index) {
- case BUTTON_SELECT:
- case BUTTON_START:
- case BUTTON_A:
- case BUTTON_B:
- case BUTTON_X:
- case BUTTON_Y:
- case BUTTON_L1:
- case BUTTON_R1:
- case BUTTON_L2:
- case BUTTON_R2:
- case BUTTON_COIN:
- Joystick.setButton(index, current_state);
- break;
- default:
- // How?
- break;
- }
- last_button_state[index] = current_state;
- }
- }
- for (int index = 0; index < JOY_BUTTON_COUNT; index++)
- {
- int current_state = !digitalRead(joy_button_pins[index]);
- if (current_state != last_joy_button_state[index])
- {
- switch (index) {
- case JOY_UP:
- if (current_state == 1) {
- Joystick.setYAxis(-1);
- } else {
- Joystick.setYAxis(0);
- }
- break;
- case JOY_RIGHT:
- if (current_state == 1) {
- Joystick.setXAxis(1);
- } else {
- Joystick.setXAxis(0);
- }
- break;
- case JOY_DOWN:
- if (current_state == 1) {
- Joystick.setYAxis(1);
- } else {
- Joystick.setYAxis(0);
- }
- break;
- case JOY_LEFT:
- if (current_state == 1) {
- Joystick.setXAxis(-1);
- } else {
- Joystick.setXAxis(0);
- }
- break;
- }
- last_joy_button_state[index] = current_state;
- }
- }
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement