Arduiblog
FRANCE • + Follow
Edit Project
Components
|
Arduino Leonardo with Headers |
x 1 | |
|
B2B-XH-A |
x 11 | |
|
B5B-XH-A |
x 1 |
Description
Arcade Shield V1
Replace the card supplied in the Arcade Kit
With an Arduino Leonardo.
More information on my blog and on Youtube.
Code
// Arcade_Shield_v1
#include <Joystick.h>
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
10, 0, // 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
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
// D18 pour l'Arduino Leonardo et D14 pour l'Arduino Uno
pinMode(18, INPUT_PULLUP);
// D19 pour l'Arduino Leonardo et D15 pour l'Arduino Uno
pinMode(19, INPUT_PULLUP);
// D20 pour l'Arduino Leonardo et D16 pour l'Arduino Uno
pinMode(20, INPUT_PULLUP);
// Si bouton Start appuyé au démarrage, pause de 30 secondes
if (digitalRead(6) == 0) {
delay(30000);
}
// Initialize Joystick Library
Joystick.begin();
Joystick.setXAxisRange(-1, 1);
Joystick.setYAxisRange(-1, 1);
}
// Last state of the buttons
int lastButtonState[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
// Leonardo
int buttonMap[14] = {2,3,4,5,6,7,8,9,10,11,12,18,19,20};
// Uno
// int buttonMap[14] = {2,3,4,5,6,7,8,9,10,11,12,14,15,16};
// ButtonMap = 0, Pin 2 = UP
// ButtonMap = 1, Pin 3 = RIGHT
// ButtonMap = 2, Pin 4 = DOWN
// ButtonMap = 3, Pin 5 = LEFT
// ButtonMap = 4, Pin 6 = Start
// ButtonMap = 5, Pin 7 = Select
// ButtonMap = 6, Pin 8 = Button 1
// ButtonMap = 7, Pin 9 = Button 2
// ButtonMap = 8, Pin 10 = Button 3
// ButtonMap = 9, Pin 11 = Button 4
// ButtonMap = 10, Pin 12 = Button 5
// ButtonMap = 11, Pin A0 (18 ou 14) = Button 6
// ButtonMap = 12, Pin A1 (19 ou 15) = Button 7
// ButtonMap = 13, Pin A2 (20 ou 16) = Button 8
void loop() {
// Read pin values
for (int index = 0; index < 14; index++)
{
int currentButtonState = !digitalRead(buttonMap[index]);
if (currentButtonState != lastButtonState[index])
{
switch (index) {
case 0: // UP
if (currentButtonState == 1) {
Joystick.setYAxis(-1);
} else {
Joystick.setYAxis(0);
}
break;
case 1: // RIGHT
if (currentButtonState == 1) {
Joystick.setXAxis(1);
} else {
Joystick.setXAxis(0);
}
break;
case 2: // DOWN
if (currentButtonState == 1) {
Joystick.setYAxis(1);
} else {
Joystick.setYAxis(0);
}
break;
case 3: // LEFT
if (currentButtonState == 1) {
Joystick.setXAxis(-1);
} else {
Joystick.setXAxis(0);
}
break;
case 4: // Start Button
Joystick.setButton(0, currentButtonState);
break;
case 5: // Select Button
Joystick.setButton(1, currentButtonState);
break;
case 6: // Button 1
Joystick.setButton(2, currentButtonState);
break;
case 7: // Button 2
Joystick.setButton(3, currentButtonState);
break;
case 8: // Button 3
Joystick.setButton(4, currentButtonState);
break;
case 9: // Button 4
Joystick.setButton(5, currentButtonState);
break;
case 10: // Button 5
Joystick.setButton(6, currentButtonState);
break;
case 11: // Button 6
Joystick.setButton(7, currentButtonState);
break;
case 12: // Button 7
Joystick.setButton(8, currentButtonState);
break;
case 13: // Button 8
Joystick.setButton(9, currentButtonState);
break;
}
lastButtonState[index] = currentButtonState;
}
}
delay(10);
}
Sep 09,2024
281 views
Arcade Shield V1
Build an Arcade controller for RecalBox
281
1
0
Published: Sep 09,2024
Download Gerber file 1
Purchase
Donation Received ($)
PCBWay Donate 10% cost To Author
*PCBWay community is a sharing platform. We are not responsible for any design issues and parameter issues (board thickness, surface finish, etc.) you choose.
Copy this HTML into your page to embed a link to order this shared project
Copy
Under the
Attribution-NonCommercial-ShareAlike (CC BY-NC-SA)
License.
- Comments(0)
- Likes(1)
Upload photo
You can only upload 5 files in total. Each file cannot exceed 2MB. Supports JPG, JPEG, GIF, PNG, BMP
0 / 10000
It looks like you have not written anything. Please add a comment and try again.
You can upload up to 5 images!
Image size should not exceed 2MB!
File format not supported!
View More
- Engineer Sep 29,2024
View More
VOTING
0 votes
- 0 USER VOTES
0.00
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Design
1/4
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Usability
2/4
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Creativity
3/4
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Content
4/4
More by Arduiblog
You may also like
-
-
-
-
-
-
3D printed Enclosure Backplate for Riden RD60xx power supplies
153 1 1 -
-