Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Joystick.h>
- Joystick_ Joystick;
- void setup() {
- // Initialize Button Pins
- pinMode(0, INPUT_PULLUP);
- pinMode(1, INPUT_PULLUP);
- pinMode(2, INPUT_PULLUP);
- pinMode(3, INPUT_PULLUP);
- pinMode(4, INPUT_PULLUP);
- pinMode(5, INPUT_PULLUP);
- pinMode(6, INPUT_PULLUP);
- pinMode(7, INPUT_PULLUP);
- pinMode(8, INPUT_PULLUP);
- pinMode(9, INPUT_PULLUP);
- pinMode(10, INPUT_PULLUP);
- // Initialize Joystick Library
- Joystick.begin();
- }
- // Constant that maps the phyical pin to the joystick button.
- const int pinToButtonMap = 0;
- // Last state of the button
- int lastButtonState[11] = {0,0,0,0,0,0,0,0,0,0,0};
- void loop() {
- // Read pin values
- for (int index = 0; index <= 10; index++)
- {
- int currentButtonState = !digitalRead(index + pinToButtonMap);
- if (currentButtonState != lastButtonState[index])
- {
- Joystick.setButton(index, currentButtonState);
- lastButtonState[index] = currentButtonState;
- }
- }
- delay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement