Hola, compré un Arduino micro oficial y al principio, funcionaba perfectamente pero intentando hacer un Gamepad que simula las teclas del teclado, escribí algo mal en el código y cuando lo conecto al ordenador no para de escribir, haciendo que no pueda mover el puntero del ratón y no me deja subirle otro código
Este es el código:
#include <Keyboard.h>
// These are used as indices to other arrays
enum {
UP,
RIGHT,
DOWN,
LEFT,
A,
B,
X,
Y,
SELECT,
START,
RESET,
// Number of keys
NUM_KEYS,
};
// Maps button index to digital pin
const int PINS[] = {
2, // UP
3, // RIGHT
5, // DOWN
4, // LEFT
10, // A
9, // B
12, // X
11, // Y
8, // SELECT
7, // START
6, //RESET
};
// Maps button to keyboard key
const char KEYS[] = {
KEY_UP_ARROW, // UP
KEY_RIGHT_ARROW, // RIGHT
KEY_DOWN_ARROW, // DOWN
KEY_LEFT_ARROW, // LEFT
'a', // A
'b', // B
'x', // X
'y', // Y
KEY_RETURN, // SELECT
' ', // START
'r' //RESET
};
// Store previous state of keys
bool STATES[NUM_KEYS];
// Initialize
void setup() {
Keyboard.begin();
for (int i = 0; i < NUM_KEYS; i++) {
pinMode(PINS[i], INPUT_PULLUP);
STATES[i] = digitalRead(PINS[i]);
}
}
// Main loop
void loop() {
bool state;
// Process each key
for (int i = 0; i < NUM_KEYS; i++) {
state = digitalRead(PINS[i]);
if (STATES[i] != state) {
if (state == LOW) {
Keyboard.press(KEYS[i]);
} else {
Keyboard.release(KEYS[i]);
}
STATES[i] = state;
}
}
}
Espero que me puedan ayudar,
gracias.