Stap 1: De Code
De code is lang, maar zijn essentiële stukken zijn eenvoudig. Hier is het:
#include < Esplora.h >
Booleaanse buttonStates [8];
Const byte knoppen [] {} =
JOYSTICK_DOWN,
JOYSTICK_LEFT,
JOYSTICK_UP,
JOYSTICK_RIGHT,
SWITCH_RIGHT,
SWITCH_LEFT,
SWITCH_UP,
SWITCH_DOWN,
};
const char toetsaanslagen [] {} =
DE ',
'A',
'W',
HAD',
'Q ',
'X',
'T',
'Z'
};
U kunt de toetsen wijzigen aan wat u wilt.
VOID Setup {}
Keyboard.begin();
}
void loop {}
voor (byte thisButton = 0; thisButton < 8; thisButton ++) {}
Boole lastState = buttonStates [thisButton];
Boole newState = Esplora.readButton(buttons[thisButton]);
Als (lastState! = newState) {}
Als (newState == PRESSED) {}
Keyboard.Press(Keystrokes[thisButton]);
}
else if (newState == RELEASED) {}
Keyboard.release(Keystrokes[thisButton]);
}
}
buttonStates [thisButton] = newState;
}
delay(50);
int xAxis = Esplora.readAccelerometer(X_AXIS);
Als (xAxis < 0) {Keyboard.press('E'); delay(50);
};
Als (xAxis > 50) {}
Keyboard.Press('Q');
delay(50);
};
delay(50);
}