Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * tinkerBOY's usb_gamepad v1.0
- *
- */
- #include <Joystick.h>
- #define PINS 5
- #define ENABLE_ANALOG1 true
- Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD, PINS, 0,
- true, true, false, false, false, false, false, false, false, false, false);
- class CButton {
- public:
- int pin = NULL;
- int lastState = 0;
- CButton(int p) {
- pin = p;
- }
- };
- CButton Buttons[PINS] ={0,1,2,3,4};
- void setup() {
- for(int i=0 ; i<PINS ;i++) {
- pinMode(Buttons[i].pin, INPUT_PULLUP);
- }
- Joystick.begin();
- Joystick.setXAxisRange(-512, 512);
- Joystick.setYAxisRange(-512, 512);
- }
- void JButtonStates() {
- // Read the state of the 4 joystick direction switches and present as analog stick movement to the host
- // I don't know how to incorporate these into the loop below :(
- // Joystick.setXAxis(digitalRead(1) * 512 - 512);
- // Joystick.setXAxis(!digitalRead(2) * 512);
- // Joystick.setYAxis(digitalRead(3) * 512 - 512);
- // Joystick.setYAxis(!digitalRead(4) * 512);
- // for (int i = 0; i < PINS; i++) {
- int currentState = !digitalRead(Buttons[0].pin);
- if (currentState != Buttons[0].lastState) {
- Joystick.setButton(0, currentState);
- Buttons[0].lastState = currentState;
- }
- }
- //}
- void loop() {
- JButtonStates();
- delay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement