Arduiblog
FRANCE • + Follow
Edit Project
Components
|
Arduino Leonardo with Headers |
x 1 | |
|
B3B-XH-AJST
|
x 1 | |
|
B5B-XH-A |
x 1 |
Description
Arcade Shield V2.1
Buttons flash when pressed. And when the controller is plugged in, it can be animated.
Simply connect the card to the joystick and buttons.
More information on my blog.
Code
// Arcade_Shield_v2
#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
// Registre_a_decalage MC74HC595AN
// D21 pour l'Arduino Leonardo et D17 pour l'Arduino Uno
const int MEMORISATION = 23; // SER
// D22 pour l'Arduino Leonardo et D18 pour l'Arduino Uno
const int AFFICHAGE = 22; // RCLK
// D23 pour l'Arduino Leonardo et D19 pour l'Arduino Uno
const int BIT = 21; // SRCLK
// Mesure du temps
unsigned long tempsEcoule = millis();
void setup() {
// Boutons
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);
//Registre_a_decalage
pinMode(BIT, OUTPUT);
pinMode(AFFICHAGE, OUTPUT);
pinMode(MEMORISATION, OUTPUT);
// Par sécurité, si bouton Start appuyé au démarrage
// la manette n'est pas activée
if (digitalRead(6) == 0) {
// Boucle infinie
while(digitalRead(6) == 0) {
clignoteTout(400);
}
}
// Animation (qui allume toutes les LED)
animationDebut(3000);
// Initialize Joystick Library
Joystick.begin();
Joystick.setXAxisRange(-1, 1);
Joystick.setYAxisRange(-1, 1);
}
int currentButtonState;
// 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++) {
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);
affichageLED(B01111111);
break;
case 7: // Button 2
Joystick.setButton(3, currentButtonState);
affichageLED(B10111111);
break;
case 8: // Button 3
Joystick.setButton(4, currentButtonState);
affichageLED(B11011111);
break;
case 9: // Button 4
Joystick.setButton(5, currentButtonState);
affichageLED(B11101111);
break;
case 10: // Button 5
Joystick.setButton(6, currentButtonState);
affichageLED(B11110111);
break;
case 11: // Button 6
Joystick.setButton(7, currentButtonState);
affichageLED(B11111011);
break;
case 12: // Button 7
Joystick.setButton(8, currentButtonState);
affichageLED(B11111101);
break;
case 13: // Button 8
Joystick.setButton(9, currentButtonState);
affichageLED(B11111110);
break;
}
lastButtonState[index] = currentButtonState;
}
}
if ((millis() - tempsEcoule) >= 80){
affichageLED(B11111111);
}
delay(10);
}
void animationDebut(int duree){
affichageLED(B00000000);
delay(duree/8);
affichageLED(B10000000);
delay(duree/8);
affichageLED(B10100000);
delay(duree/8);
affichageLED(B10101000);
delay(duree/8);
affichageLED(B10101010);
delay(duree/8);
affichageLED(B10101011);
delay(duree/8);
affichageLED(B10101111);
delay(duree/8);
affichageLED(B10111111);
delay(duree/8);
affichageLED(B11111111);
}
void clignoteTout(int duree){
affichageLED(B11111111);
delay(duree/2);
affichageLED(B00000000);
delay(duree/2);
}
int affichageLED(int leds){
digitalWrite(AFFICHAGE,LOW);
shiftOut(BIT, MEMORISATION, LSBFIRST, leds);
digitalWrite(AFFICHAGE,HIGH);
tempsEcoule = millis(); //Mise à jour du temps
}
Sep 29,2024
131 views
Arcade Shield V2.1
Version 2.1 allows you to control button LEDs
131
1
0
Published: Sep 29,2024
Download Gerber file 1
BOM(Bill of materials)
Purchase
Donation Received ($)
PCBWay Donate 10% cost To Author
File Last Updated: 2024/09/30 (GMT+8)
File update record
2024-09-3018:59:28
Parts List (BOM) is updated.
Only PCB
PCB+Assembly
*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-ShareAlike (CC BY-SA)
License.
- Comments(0)
- Likes(1)
You can only upload 1 files in total. Each file cannot exceed 2MB. Supports JPG, JPEG, GIF, PNG, BMP
0 / 10000
Remove
It looks like you have not written anything. Please add a comment and try again.
View More
- Engineer Oct 01,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
65 1 1 -
-
-
-
Sega Master System RGB Encoder Switcher Z80 QSB v1.2
65 0 0 -
18650 2S2P Battery Charger, Protection and 5V Output Board
90 0 0 -
High Precision Thermal Imager + Infrared Thermometer | OpenTemp
463 0 7 -
Sony PlayStation Multi Output Frequency Oscillator (MOFO) v1
137 0 2 -