Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Bounce.h>
- #define NUM_BUTTONS 16 //(inc directional buttons)
- #define A_PIN 15
- #define B_PIN 16
- #define X_PIN 14
- #define Y_PIN 17
- #define RJOY_SEL_PIN 18
- #define RJOY_X_PIN 6 //analog
- #define RJOY_Y_PIN 7 //analog
- #define LJOY_SEL_PIN 7
- #define LJOY_X_PIN 8 //analog
- #define LJOY_Y_PIN 9 //analog
- #define R_PIN 8
- #define D_PIN 9
- #define L_PIN 10
- #define U_PIN 11
- #define LSHOL_PIN 0
- #define LTRIG_PIN 1
- #define RSHOL_PIN 2
- #define RTRIG_PIN 3
- #define SELECT_PIN 5
- #define START_PIN 6
- Bounce btn_x = Bounce(X_PIN, 10);
- Bounce btn_a = Bounce(A_PIN, 10);
- Bounce btn_b = Bounce(B_PIN, 10);
- Bounce btn_y = Bounce(Y_PIN, 10);
- Bounce btn_Rjoysel = Bounce(RJOY_SEL_PIN, 10);
- Bounce btn_up = Bounce(U_PIN, 10);
- Bounce btn_right = Bounce(R_PIN, 10);
- Bounce btn_down = Bounce(D_PIN, 10);
- Bounce btn_left = Bounce(L_PIN, 10);
- Bounce btn_Ljoysel = Bounce(LJOY_SEL_PIN, 10);
- Bounce btn_RShoulder = Bounce(RSHOL_PIN, 10);
- Bounce btn_RTrigger = Bounce(RTRIG_PIN, 10);
- Bounce btn_LShoulder = Bounce(LSHOL_PIN, 10);
- Bounce btn_LTrigger = Bounce(LTRIG_PIN, 10);
- Bounce btn_start = Bounce(START_PIN, 10);
- Bounce btn_select = Bounce(SELECT_PIN, 10);
- Bounce buttons[NUM_BUTTONS] =
- {
- btn_a, //RIGHT SIDE
- btn_b,
- btn_x,
- btn_y,
- btn_Rjoysel,
- btn_up, //LEFT SIDE
- btn_right, //MAYBE SET AS HAT? need to convert to angle
- btn_down,
- btn_left,
- btn_Ljoysel,
- btn_RShoulder, //SHOULDER BUTTONS
- btn_RTrigger,
- btn_LShoulder,
- btn_LTrigger,
- btn_start, //START SELECT
- btn_select
- };
- Bounce dpad_buttons[4]{
- btn_up,
- btn_down,
- btn_left,
- btn_right
- };
- void setup() {
- // put your setup code here, to run once:
- //retropie controller setup
- pinMode(13, OUTPUT);
- digitalWrite(13, HIGH);
- pinMode(A_PIN, INPUT_PULLUP);
- pinMode(B_PIN, INPUT_PULLUP);
- pinMode(X_PIN, INPUT_PULLUP);
- pinMode(Y_PIN, INPUT_PULLUP);
- pinMode(RJOY_SEL_PIN, INPUT_PULLUP);
- pinMode(U_PIN, INPUT_PULLUP);
- pinMode(D_PIN, INPUT_PULLUP);
- pinMode(R_PIN, INPUT_PULLUP);
- pinMode(L_PIN, INPUT_PULLUP);
- pinMode(LJOY_SEL_PIN, INPUT_PULLUP);
- pinMode(RTRIG_PIN, INPUT_PULLUP);
- pinMode(RSHOL_PIN, INPUT_PULLUP);
- pinMode(LTRIG_PIN, INPUT_PULLUP);
- pinMode(LSHOL_PIN, INPUT_PULLUP);
- pinMode(START_PIN, INPUT_PULLUP);
- pinMode(SELECT_PIN, INPUT_PULLUP);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- Joystick.X(map(analogRead(LJOY_X_PIN), 0, 1023, 1023, 0));
- Joystick.Y(analogRead(LJOY_Y_PIN));
- Joystick.Z(analogRead(RJOY_Y_PIN));
- Joystick.Zrotate(analogRead(RJOY_X_PIN));
- for(int i = 0; i < NUM_BUTTONS; i++){
- buttons[i].update();
- if(buttons[i].fallingEdge()){
- Joystick.button(i+1, 1);
- }
- if(buttons[i].risingEdge()){
- Joystick.button(i+1, 0);
- }
- }
- uint8_t readDPad =0;
- // for(int i = 0; i < 4; i++){
- // dpad_buttons[i].update();
- // readDPad |= !(dpad_buttons[i].read()) << i;
- // }
- // switch(readDPad){
- // //up 1
- // //down 2
- // //left 4
- // //right 8
- // case 1:
- // Joystick.hat(0); //N
- // break;
- // case 2:
- // Joystick.hat(180);//S
- // break;
- // case 4:
- // Joystick.hat(270);//W
- // break;
- // case 8:
- // Joystick.hat(90); //E
- // break;
- // case 5:
- // Joystick.hat(315);//NW
- // break;
- // case 9:
- // Joystick.hat(45); //NE
- // break;
- // case 6:
- // Joystick.hat(225);//SW
- // break;
- // case 10:
- // Joystick.hat(135);//SE
- // break;
- // default:
- // Joystick.hat(-1); //CENTRE
- // break;
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment