Created
December 23, 2012 14:40
-
-
Save anonymous/4363732 to your computer and use it in GitHub Desktop.
arduino SNESpad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SNESpad.h> | |
#define STROBE 1 | |
#define CLOCK 3 | |
#define DATA 5 | |
SNESpad pad = SNESpad(STROBE,CLOCK,DATA); | |
int wheel; | |
int defaultSpeed; | |
int changeSpeed = 0; | |
boolean isbegin = false; | |
void setup(); | |
void loop(); | |
void setup() | |
{ | |
Serial.begin(115200); | |
} | |
void loop() | |
{ | |
defaultSpeed = 2; | |
wheel = 1; | |
int input; | |
// SNES_B, SNES_Y, SNES_A, SNES_X | |
// SNES_UP, SNES_DOWN, SNES_LEFT, SNES_RIGHT | |
// SNES_SELECT, SNES_START, SNES_L, SNES_R | |
input = pad.buttons(); | |
if(input & SNES_SELECT){ | |
// mouse emulate end | |
Mouse.end(); | |
isbegin = false; | |
}else if(input & SNES_START){ | |
// mouse emulate start | |
Mouse.begin(); | |
isbegin = true; | |
} | |
if(input == (SNES_START + SNES_UP)){ | |
changeSpeed++; | |
delay(100); | |
}else if(input == (SNES_START + SNES_DOWN)){ | |
changeSpeed--; | |
if(changeSpeed < 0){ | |
changeSpeed = 0; | |
} | |
delay(100); | |
} | |
if(isbegin){ | |
// button release if press button | |
if((Mouse.isPressed() || Mouse.isPressed(MOUSE_RIGHT) || Mouse.isPressed(MOUSE_MIDDLE)) && input == 0){ | |
if(Mouse.isPressed()){ | |
Mouse.release(); | |
}else if(Mouse.isPressed(MOUSE_RIGHT)){ | |
Mouse.release(MOUSE_RIGHT); | |
}else if(Mouse.isPressed(MOUSE_MIDDLE)){ | |
Mouse.release(MOUSE_MIDDLE); | |
} | |
} | |
// command A, B, X, Y | |
if(input & SNES_A){ | |
Mouse.press(); | |
input -= SNES_A; | |
}else if(input & SNES_B){ | |
// speed up | |
defaultSpeed = changeSpeed + 4; | |
wheel = 3; | |
input -= SNES_B; | |
}else if(input & SNES_X){ | |
Mouse.press(MOUSE_MIDDLE); | |
input -= SNES_X; | |
}else if(input & SNES_Y){ | |
// default MOUSE_LEFT | |
Mouse.press(MOUSE_RIGHT); | |
input -= SNES_Y; | |
} | |
// move cursor | |
int mouseSpeed = defaultSpeed + changeSpeed; | |
if(input == (SNES_UP + SNES_LEFT)){ | |
Mouse.move(-mouseSpeed, -mouseSpeed, 0); | |
}else if(input == (SNES_LEFT + SNES_DOWN)){ | |
Mouse.move(-mouseSpeed, mouseSpeed, 0); | |
}else if(input == (SNES_DOWN + SNES_RIGHT)){ | |
Mouse.move(mouseSpeed, mouseSpeed, 0); | |
}else if(input == (SNES_RIGHT + SNES_UP)){ | |
Mouse.move(mouseSpeed, -mouseSpeed, 0); | |
}else{ | |
if(input & SNES_UP){ | |
Mouse.move(0, -mouseSpeed, 0); | |
}else if(input & SNES_LEFT){ | |
Mouse.move(-mouseSpeed, 0, 0); | |
}else if(input & SNES_DOWN){ | |
Mouse.move(0, mouseSpeed, 0); | |
}else if(input & SNES_RIGHT){ | |
Mouse.move(mouseSpeed, 0, 0); | |
} | |
} | |
// scroll page | |
if(input & SNES_L){ | |
Mouse.move(0, 0, wheel); | |
}else if(input & SNES_R){ | |
Mouse.move(0,0, -(wheel)); | |
} | |
} | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment