w/ HID lib not working

This commit is contained in:
Tropicananass 2020-04-19 00:52:23 +02:00
parent a31018fa9e
commit 99a3973e90
3 changed files with 40 additions and 2 deletions

View File

@ -8,6 +8,9 @@
; Please visit documentation for the other options and examples ; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[env]
lib_deps = HID-Project
[env:sparkfun_promicro16] [env:sparkfun_promicro16]
platform = atmelavr platform = atmelavr
board = sparkfun_promicro16 board = sparkfun_promicro16

BIN
res/ProMicro16MHzv2.pdf Normal file

Binary file not shown.

View File

@ -1,9 +1,44 @@
#include <Arduino.h> #include <Arduino.h>
#include <HID-Project.h>
#define NUM_KEYS 12
uint8_t const pin_lr{2};
uint8_t const pin_rr{A3};
uint8_t const pin_left{5};
uint8_t const pin_up{3};
uint8_t const pin_down{7};
uint8_t const pin_right{6};
uint8_t const pin_y{A2};
uint8_t const pin_x{15};
uint8_t const pin_b{A0};
uint8_t const pin_a{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, ' ' };
bool states [] = {LOW , LOW , LOW , LOW , LOW , LOW , LOW , LOW , LOW , LOW , LOW , LOW };
void setup() { void setup() {
// put your setup code here, to run once: Gamepad.begin();
for (size_t i = 0; i < NUM_KEYS; ++i) {
pinMode(pin_array[i], INPUT_PULLUP);
states[i] = digitalRead(pin_array[i]);
}
} }
void loop() { void loop() {
// put your main code here, to run repeatedly: bool current_state;
for (size_t i = 0; i < NUM_KEYS; ++i) {
current_state = digitalRead(pin_array[i]);
if (current_state != states[i]) {
if (current_state == LOW) {
Gamepad.press(key_array[i]);
} else {
Gamepad.release(key_array[i]);
}
states[i] = current_state;
}
}
} }