joystick lib

This commit is contained in:
Tropicananass 2020-04-19 01:44:57 +02:00
parent 99a3973e90
commit 28d9217385
2 changed files with 9 additions and 6 deletions

View File

@ -9,7 +9,7 @@
; https://docs.platformio.org/page/projectconf.html
[env]
lib_deps = HID-Project
lib_deps = Joystick
[env:sparkfun_promicro16]
platform = atmelavr

View File

@ -1,5 +1,5 @@
#include <Arduino.h>
#include <HID-Project.h>
#include <Joystick.h>
#define NUM_KEYS 12
@ -17,11 +17,14 @@ uint8_t const pin_select{9};
uint8_t const pin_start{10};
uint8_t const pin_array[] = {pin_lr, pin_rr, pin_left , pin_up , pin_right , pin_down , pin_y, pin_x, pin_b, pin_a, pin_select, pin_start};
int const key_array[] = {'r' , 'l' , GAMEPAD_DPAD_LEFT, GAMEPAD_DPAD_UP, GAMEPAD_DPAD_RIGHT, GAMEPAD_DPAD_DOWN, 'y' , 'x' , 'b' , 'a' , KEY_RETURN, ' ' };
// uin8__t const key_array[] = {0, 1, 2, 3, 4, 5, };
// int const key_array[] = {'r' , 'l' , GAMEPAD_DPAD_LEFT, GAMEPAD_DPAD_UP, GAMEPAD_DPAD_RIGHT, GAMEPAD_DPAD_DOWN, 'y' , 'x' , 'b' , 'a' , KEY_RETURN, ' ' };
bool states [] = {LOW , LOW , LOW , LOW , LOW , LOW , LOW , LOW , LOW , LOW , LOW , LOW };
Joystick_ Joystick;
void setup() {
Gamepad.begin();
Joystick.begin();
for (size_t i = 0; i < NUM_KEYS; ++i) {
pinMode(pin_array[i], INPUT_PULLUP);
states[i] = digitalRead(pin_array[i]);
@ -34,9 +37,9 @@ void loop() {
current_state = digitalRead(pin_array[i]);
if (current_state != states[i]) {
if (current_state == LOW) {
Gamepad.press(key_array[i]);
Joystick.pressButton(i);
} else {
Gamepad.release(key_array[i]);
Joystick.releaseButton(i);
}
states[i] = current_state;
}