.......... Uh oh, deleted the whole first post. Now I must fear the wrath of PaulS
Moderator edit: Code replaced from my copy. Thread locked.
#include <SNESpaduino.h>
int isChangeMode=0; //Used to wait until user stops holding mode change buttons before continuing.
int currentMode=0; //Mode 0 is KEYBOARD mode, Mode 1 is JOYPAD mode.
SNESpaduino pad(2, 3, 4);
uint16_t btns;
JoyState_t joySt;
/* SETUP */
void setup()
{
Keyboard.begin();
joySt.xAxis = 127;
joySt.yAxis = 127;
joySt.buttons = 0;
}
void releaseKey()
{
joySt.buttons = joySt.buttons & 254;
joySt.buttons = joySt.buttons & 253;
joySt.buttons = joySt.buttons & 252;
joySt.buttons = joySt.buttons & 251;
joySt.buttons = joySt.buttons & 250;
joySt.buttons = joySt.buttons & 249;
joySt.buttons = joySt.buttons & 255;
joySt.buttons = joySt.buttons & 256;
joySt.yAxis = 127;
joySt.xAxis = 127;
}
void loop()
{
btns = pad.getButtons();
if ((btns & BTN_UP) && (btns & BTN_SELECT)) { //If the change-mode key combo is pressed
if(isChangeMode==0){
if(currentMode==0) {
Keyboard.releaseAll();
currentMode=1;
isChangeMode=1;
}
else {
Keyboard.releaseAll();
currentMode=0;
isChangeMode=1;
}
}
isChangeMode=1;
}
else {
isChangeMode=0;
}
//UP
if(btns & BTN_UP){
if(currentMode==0)
{
Keyboard.press(KEY_UP_ARROW);
}
else
{
joySt.yAxis = 0;
}
}
else{
if(currentMode==0)
{
Keyboard.release(KEY_UP_ARROW);
}
}
//DOWN
if(btns & BTN_DOWN){
if(currentMode==0)
{
Keyboard.press(KEY_DOWN_ARROW);
}
else
{
joySt.yAxis = 255;
}
}
else{
if(currentMode==0)
{
Keyboard.release(KEY_DOWN_ARROW);
}
}
//LEFT
if(btns & BTN_LEFT){
if(currentMode==0)
{
Keyboard.press(KEY_LEFT_ARROW);
}
else
{
joySt.xAxis = 0;
}
}
else{
if(currentMode==0)
{
Keyboard.release(KEY_LEFT_ARROW);
}
}
//RIGHT
if(btns & BTN_RIGHT){
if(currentMode==0)
{
Keyboard.press(KEY_RIGHT_ARROW);
}
else
{
joySt.xAxis = 255;
}
}
else{
if(currentMode==0)
{
Keyboard.release(KEY_RIGHT_ARROW);
}
}
//SELECT
if(btns & BTN_SELECT){
if(currentMode==0)
{
Keyboard.press(',');
}
else
{
joySt.buttons = joySt.buttons | 1;
}
}
else{
if(currentMode==0)
{
Keyboard.release(',');
}
}
//START
if(btns & BTN_START){
if(currentMode==0)
{
Keyboard.press('.');
}
else
{
joySt.buttons = joySt.buttons | 2;
}
}
else{
if(currentMode==0)
{
Keyboard.release('.');
}
}
//A
if(btns & BTN_A){
if(currentMode==0)
{
Keyboard.press('x');
}
else
{
joySt.buttons = joySt.buttons | 4;
}
}
else{
if(currentMode==0)
{
Keyboard.release('x');
}
}
//B
if(btns & BTN_B){
if(currentMode==0)
{
Keyboard.press('z');
}
else
{
joySt.buttons = joySt.buttons | 8;
}
}
else{
if(currentMode==0)
{
Keyboard.release('z');
}
}
//X
if(btns & BTN_X){
if(currentMode==0)
{
Keyboard.press('v');
}
else
{
joySt.buttons = joySt.buttons | 16;
}
}
else{
if(currentMode==0)
{
Keyboard.release('v');
}
}
//Y
if(btns & BTN_Y){
if(currentMode==0)
{
Keyboard.press('c');
}
else
{
joySt.buttons = joySt.buttons | 32;
}
}
else{
if(currentMode==0)
{
Keyboard.release('c');
}
}
//L
if(btns & BTN_L){
if(currentMode==0)
{
Keyboard.press('l');
}
else
{
joySt.buttons = joySt.buttons | 64;
}
}
else{
if(currentMode==0)
{
Keyboard.release('l');
}
}
//R
if(btns & BTN_R){
if(currentMode==0)
{
Keyboard.press('r');
}
else
{
joySt.buttons = joySt.buttons | 128;
}
}
else{
if(currentMode==0)
{
Keyboard.release('r');
}
}
//Key combinations
if (btns & BTN_SELECT)
{
if (btns & BTN_START)
{
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press('r');
Keyboard.release('r');
Keyboard.release(KEY_LEFT_GUI);
delay(500);
Keyboard.print("W:");
Keyboard.write(47);
Keyboard.print("Arcade");
Keyboard.write(47);
Keyboard.print("Program.exe");
delay(1500);
Keyboard.write(179);
Keyboard.write(32);
}
else
{
Keyboard.release('r');
Keyboard.release(KEY_LEFT_GUI);
}
if (btns & BTN_SELECT)
{
if (btns & BTN_L)
{
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_F4);
}
else
{
Keyboard.release(KEY_F4);
Keyboard.release(KEY_LEFT_ALT);
}
}
if (btns & BTN_SELECT)
{
if (btns & BTN_R)
{
Keyboard.press(KEY_ESC);
}
else
{
Keyboard.release(KEY_ESC);
}
}
}
// Send joystick state
Joystick.setState(&joySt);
//Release Buttons
releaseKey();
}